def handle(bot, update): # import ipdb; ipdb.set_trace() f = bot.getFile(update.message.photo[-1].file_id) fn = "files/{}.jpg".format(time.time()) f.download(fn) guess = run_inference_on_image(fn) bot.sendMessage(chat_id=update.message.chat_id, text="I think it is a {}".format(guess))
def PIC_classify_pic_func(self): if self.imported: classification = run_inference_on_image(self.my_directory_path + '/images/import_dream') self.pic_classification = classification self.PIC_description.setText(classification) else: self.PIC_LC.setText("Import a picture first")
def NF_classify_pic_func(self): if self.first_dream: classification = run_inference_on_image(self.my_directory_path + '/images/default') self.nf_classification = classification self.NF_description.setText(classification) else: self.NF_LC.setText("Dream a picture first")
def post(self): fileinfo = self.request.files['file'][0] # print "fileinfo is", fileinfo fname = fileinfo['filename'] extn = os.path.splitext(fname)[1] cname = str(uuid.uuid4()) + extn filePath = __UPLOADS__ + cname fh = open(filePath, 'w') fh.write(fileinfo['body']) fh.close() keywords = classify.run_inference_on_image(filePath) self.write(json_encode(keywords))
def image_rec(bot, update): # import ipdb; ipdb.set_trace() f = bot.getFile(update.message.photo[-1].file_id) fn = "files/{}.jpg".format(time.time()) f.download(fn) resp = run_inference_on_image(fn) obj_info = search_info_by_id(mapping(resp)) print(obj_info) if obj_info[2] == '1': obj_inf = "принимаем" else: obj_inf = "не принимаем" bot.sendMessage(chat_id=update.message.chat_id, text='Это {} и это мы {}'.format(obj_info[0], obj_inf)) bot.sendMessage(chat_id=update.message.chat_id, text=resp)
def put(self): try: # Parse the arguments parser = reqparse.RequestParser() parser.add_argument('user_id', type=str, help='user_id') parser.add_argument('filename', type=str, help='Class of shared waste') parser.add_argument('file', type=werkzeug.FileStorage, location='files', help='Class of shared waste') args = parser.parse_args() print(args) _userid = args['user_id'] _filename = args['filename'] _file = args['file'].stream if not os.path.exists(_FOLDER_4_RCGN_): os.makedirs(_FOLDER_4_RCGN_) request_id = uuid.uuid1().__str__() fn = "[{}]-[{}]-[{}]-{}".format(request_id, _userid, time.time(), translit(_filename, reversed=True)) full_fn = _FOLDER_4_RCGN_ + "/" + fn with open(full_fn, 'wb') as fout: fout.write(_file.getvalue()) resultFlag = True # # #resp = "сеть скорей всего не работает. печаль!!!" print(full_fn) try: resp = run_inference_on_image(full_fn) print(resp) except Exception as e: resultFlag = False print(e) # # # result = '' try: with codecs.open("recycle_db.csv", encoding='utf-8') as csvfile: reader = csv.reader(csvfile, delimiter=',', quotechar='"') for rec in reader: if rec[2] in resp or resp in rec[2]: result = rec[1] if result == '': result = "не удалось определить класс отходов" pass except Exception as e: print(e) if 'disposable paper cups resize' in resp: result = "бумажный стакан" if 'lame foil' in resp: result = "фольга" if 'glass bottle' in resp: result = "стеклянная бутылка" if 'plastic bottle' in resp: result = "пластиковая бутылка" if 'stupid' in resp: result = "неудалось определить класс отходов" if 'receipt' in resp: result = "чек" pass return { 'StatusCode': '200', 'Message': result, 'callback_id': request_id } except Exception as e: return {'error': str(e)}
def test_inference(image_name, animal_name): # Ignore score in case it varies slightly on different platforms. # Just check the name. human_readable_name, _ = run_inference_on_image(image_name) assert human_readable_name == animal_name