def get_images_by_object_id(object_id, offset=0, limit=10): log.info('get_images_by_object_id') search = Search(log) user_api = Users() res = GetImageResponse() log_dic = {} log_dic['device_id'] = 'bluehackmaster' log_dic['object_id'] = object_id rconn.lpush(REDIS_LOG_SEARCH_OBJECT_ID_QUEUE, pickle.dumps(log_dic)) try: object_d = rconn.hget(REDIS_USER_OBJECT_HASH, object_id) if object_d != None: images = pickle.loads(object_d) else: object = user_api.get_object(object_id) images = search.get_images_by_object_vector(object['feature'], limit=limit) images_list = [] if images is None: res.message = "Successful, but there is no similar images" res.data = None response_status = 400 else: for image in images: images_list.append(Image().from_dict(image)) res.message = "Successful" res.data = images_list response_status = 200 except Exception as e: log.error(str(e)) response_status = 400 return res, response_status
from __future__ import print_function from stylelens_user.users import Users from pprint import pprint api_instance = Users() device_id = "xxxx" try: api_response = api_instance.get_user_by_device_id(device_id) pprint(api_response) except Exception as e: print("Exception when calling get_user_by_device_id: %s\n" % e)
def get_objects_by_user_image_file(file): search = Search(log) res = GetObjectsResponse() if file and allowed_file(file.filename): im = PIL.Image.open(file.stream) format = im.format log.debug(im.format) try: if 'gif' == format.lower(): log.debug('gif') im.seek(0) mypalette = im.getpalette() im.putpalette(mypalette) new_im = PIL.Image.new("RGBA", im.size) new_im.paste(im) new_im.save('foo' + '.png') bg = PIL.Image.new("RGB", im.size, (255, 255, 255)) bg.paste(new_im, (0, 0), new_im) bg.save(TMP_IMG, quality=95) im = bg elif 'png' == format.lower(): log.debug('png') bg = PIL.Image.new("RGB", im.size, (255, 255, 255)) bg.paste(im, im) bg.save(TMP_IMG, quality=95) im = bg else: im.save(TMP_IMG) userImage = {} image_url = utils.save_image_to_storage( str(uuid.uuid4()), 'user', TMP_IMG) boxes, objects = search.get_objects(TMP_IMG) images = search.search_image_file(TMP_IMG) user_api = Users() box_dic_list = [] obj_ids = [] i = 0 for box in boxes: b = box.to_dict() b['feature'] = objects[i]['feature'] box_dic_list.append(b) object_id = user_api.add_object('bluehackmaster', b) box.id = object_id obj_ids.append(object_id) rconn.hset(REDIS_USER_OBJECT_HASH, object_id, pickle.dumps(b)) rconn.lpush(REDIS_USER_OBJECT_QUEUE, object_id) i = i + 1 userImage['boxes'] = box_dic_list userImage['url'] = image_url image_id = user_api.add_image('bluehackmaster', userImage) userImage['device_id'] = 'bluehackmaster' userImage['image_id'] = image_id userImage.pop('boxes') userImage['objects'] = obj_ids rconn.lpush(REDIS_LOG_SEARCH_IMAGE_FILE_QUEUE, pickle.dumps(userImage)) res_data = GetObjectsResponseData() res_data.boxes = boxes res_data.image_id = image_id images_list = [] if images is None: res.message = "Successful, but there is no similar images" res_data.images = None else: for image in images: images_list.append(Image().from_dict(image)) res.message = "Successful" res_data.images = images_list res.data = res_data response_status = 200 except Exception as e: log.error(str(e)) response_status = 400 return res, response_status
from __future__ import print_function from stylelens_user.users import Users from pprint import pprint api_instance = Users() device_id = 'xxxx' image = {} image['xxxxx'] = 'xxxx' try: api_response = api_instance.add_image(device_id, image) pprint(api_response) except Exception as e: print("Exception when calling add_object: %s\n" % e)
from __future__ import print_function from stylelens_user.users import Users from pprint import pprint api_instance = Users() device_id = 'xxxx' try: api_response = api_instance.increase_user_profile_price( device_id, 'low_mid') pprint(api_response) except Exception as e: print("Exception when calling increase_user_profile_price: %s\n" % e)
from __future__ import print_function from stylelens_user.users import Users from pprint import pprint api_instance = Users() image_id = "" object = {} object['xxxxx'] = 'xxxx' try: api_response = api_instance.add_object(object) pprint(api_response) except Exception as e: print("Exception when calling add_object: %s\n" % e)
from __future__ import print_function from stylelens_user.users import Users from pprint import pprint api_instance = Users() user = {} user['device_id'] = 'xxxx' try: api_response = api_instance.add_user(user) pprint(api_response) except Exception as e: print("Exception when calling add_user: %s\n" % e)
from __future__ import print_function from stylelens_user.users import Users from pprint import pprint api_instance = Users() device_id = 'xxxx' try: api_response = api_instance.increase_user_profile_category(device_id, 'blouse') pprint(api_response) except Exception as e: print("Exception when calling increase_user_profile_category: %s\n" % e)