def contact_handler(bot, update): upd = update.to_dict() phone_no = str('+') + upd.get('message').get('contact').get('phone_number') content['contact'] = phone_no if check_skin('./temp/' + str(update.message.chat_id) + '.jpg'): preds_dict = predict_class('./temp/' + str(update.message.chat_id) + '.jpg') dict_dis = sorted(preds_dict.items(), key=lambda x: x[1], reverse=True) print(dict_dis) dict_dis = dict(sorted(preds_dict.items(), key=lambda x: x[1], reverse=True)[:3]) max_val = max(dict_dis, key=dict_dis.get) if dict_dis[max_val] <= 39: bot.send_message(chat_id=update.message.chat_id, text='Healthy Skin Detected') else: plt.bar(range(len(dict_dis)), list(dict_dis.values()), align='center') x1,x2,y1,y2 = plt.axis() plt.axis((x1,x2,0,100)) plt.xticks(range(len(dict_dis)), range(len(dict_dis))) plt.savefig('./temp/plots/tempfig.png') bot.send_message(chat_id=update.message.chat_id, text="Thank you!\n \nYou will recieve your report Soon") bot.send_photo(chat_id=update.message.chat_id, photo=open('./temp/plots/tempfig.png', 'rb')) os.remove('./temp/plots/tempfig.png') plt.cla() keys = list(dict_dis.keys()) message_text = '0 ->' + str(keys[0]) + '\n1 ->' + str(keys[1]) + '\n2 ->' + str(keys[2]) bot.send_message(chat_id=update.message.chat_id, text=message_text) else: bot.send_message(chat_id=update.message.chat_id, text='Please Upload Infected Skin Area for Diagnosis')
def predictor(img_url, filename): model = model_load(filename) img = get_image(img_url) labels, names = get_labels(filename) predicted_id, predicted_class, confidence = predict_class( img, model, labels, names) return predicted_id, predicted_class, confidence
def home(): if request.method == 'POST': img = request.form['canvasData'] predicted_class = predict_class(img) return render_template('index.html', predicted_class=predicted_class) else: return render_template('index.html')
def get_target_image_url(): """ @param url: post : The target image url. @returns: 201 : a label (cat / dog) as a flask/response object. @raise 400: if unable to download the image. """ if not request.get_json(): abort(400) else: data = request.get_json(force=True) if not data.get('image_url'): abort(400) else: url = data.get('image_url') r = requests.get(url) image_dir = os.path.join('/media', str(url).split('/')[-1]) if not os.path.exists('/media'): os.mkdir('/media') if not os.path.exists(image_dir): with open(image_dir, 'wb') as f: f.write(r.content) status = 200 else: status = 201 class_name = predict_class(os.path.join("..", image_dir)) return jsonify({'class': class_name, 'status': status})
def main(argv): try: opts, args = getopt.getopt(argv, "htp:", ["train", "predict="]) except getopt.GetoptError: logging.info( 'Incorrect argument... \nmain.py -t or --train to train the model || main.py -p or --predict <Text> to predict on model output' ) sys.exit(2) for opt, arg in opts: if opt == '-h': logging.info( 'main.py -t or --train to train the model || main.py -p or --predict <Text> to predict on model output' ) sys.exit() elif opt in ("-t", "--train"): logging.info("training model started...") get_data = LoadTrainingData(CONFIG_PATH) df = get_data.load_data_from_tables() logging.info(f"training data loaded... {df.shape}") train_model(df) logging.info("training model finished!") elif opt in ("-p", "--predict"): text = arg if len(text) > 10: main_prouct = predict_class(text) logging.info("Prediction done!") else: logging.info("too small sentence to predict")
def predict(): data = request.get_json() data = json.dumps(data) pred, pred_proba = predict_class(model, lecancer, lerelationships, history_class_codes, ethnicity_codes, data, df) print(pred, pred_proba[0].tolist()) return_obj = { 'pred': pred, 'predProba': pred_proba[0].tolist() } return json.dumps(return_obj)
def classify_audio(): #sends username and youtube url json_data = request.json url = json_data['url'] username = json_data['username'] label = predict_class(url) if label == None: return json.dumps('error') emot = label_to_emot[label] addUrlToDb(username, emot, url) return json.dumps(emot)
def process_img(img): # time.sleep(2) preds = predict.predict_class(img) with lock: global last_object_class global last_object_count global last_object_ts global detected_object_class last_object_ts = time.time() detected_object_class = "" if last_object_class == preds and (last_object_ts - time.time()) < 1: last_object_count += 1 if last_object_count == last_object_target_count: detected_object_class = last_object_class last_object_count = 0 print(detected_object_class) else: last_object_class = copy.deepcopy(preds) last_object_count = 0 return True
from glob import glob import cv2 import numpy as np # from skin_detection import get_hist, check_skin # img_list = sorted(glob('./imgs/*.jpg')) # for img in img_list: # hist = get_hist(img) # check = check_skin(hist) # if check: # print(img, ':Skin') # else: # print(img, ':Not Skin') from predict import predict_class, classes imgs_list = ['03DermatitisArm.jpg'] # '03eczema091205.jpg', # '04acidBurn89-GP3.jpg', # 'chapped-fissured-feet-34.jpg'] for img in imgs_list: dict_dis = predict_class('./imgs/' + img) dict_dis = sorted(dict_dis.items(), key=lambda x: x[1], reverse=True) print(dict_dis[:3])
def smartatm(phrase): result = predict.predict_class(phrase) apilog.info("Predict Request : " + phrase) apilog.info("Predicted as : " + result) return result