def callback_detect(call): user_id = call.message.chat.id try: user_img = bot.captured_data_img(user_id) if user_img is not None: bot.edit_message_media( chat_id=user_id, message_id=call.message.message_id, media=InputMediaPhoto( user_img, caption=MsgTemplate.prediction_start_notice())) processed_photo = predict(user_id) bot.edit_message_media( chat_id=user_id, message_id=call.message.message_id, media=InputMediaPhoto( processed_photo, caption=MsgTemplate.prediction_end_notice())) bot.answer_callback_query(callback_query_id=call.id, show_alert=False) else: bot.send_message(user_id, MsgTemplate.captured_image_error(success=False)) except Exception: bot.send_message( user_id, MsgTemplate.captured_image_error(exception_occurred=True))
def account(update, context): if update.message.text == '/cancel': return cancel(update,context) elif update.message.text == '/start': update.message.reply_text('The bot is already active, send me the username of the account you want to verify...') return ACCOUNT else: text = update.message.text result = predict(text) currentTime = datetime.datetime.utcnow()+datetime.timedelta(hours=1) if 5 < currentTime.hour < 12: time = 'morning' elif 12 <= currentTime.hour < 18: time = 'afternoon' else: time = 'nightly' if(result != None): prediction = getPrediction(result) if (prediction == "real"): emote = '✅' elif (prediction == "fake"): emote = '❌' update.message.reply_text( 'Mhhh, {} is the one you chose...\n\n' 'This seems to be a {} {} one to me!\n' 'I\'m quite sure it is. 😉\nIt was fun, send me another one!\n' 'I\'m always up for some {} training! 👨💻'.format(text.lower(), prediction.upper(), emote, time)) else: update.message.reply_text( 'Mhhh, {} is the one you chose...\n\n' 'Have you wrote it right? 🤔 ' 'This user doesn\'t exist! But don\'t worry, retry! ' 'I\'m always up for some {} training! 👨💻'.format(text.lower(), time)) return ACCOUNT
def detectApp(): if request.method == "GET": return str( 'use post method using multipart form data, "file" as param') # filePath = './uploads/pic1.jpg' # predictions = predict(filePath, model_path ='trained_model.clf') # names = [] # for name, (top, right, bottom, left) in predictions: # print(name) # names.append(name) # return str(names) if request.method == "POST": if request.files: image = request.files["file"] filePath = os.path.join(app.config["IMAGE_UPLOADS"], image.filename).replace('\\', '/') image.save(filePath) print('\033[94m' + filePath + '\033[0m') predictions = predict(filePath, model_path='trained_model.clf') names = [] for name, (top, right, bottom, left) in predictions: print(name) names.append(name) return str(names) return 'wrong input format'
def prediction(): if request.method == "POST": form_data = request.form status = predict(form_data["sentence"]) return render_template("final.html", result=status, response=status) else: return render_template("final.html")
def f(): t0 = time.time() url = request.query.url p = predict(url) pp = predict_proba(url) t1 = time.time() pt = "Prediction time: "+str(round(t1-t0,2))+"s." return p+"\n"+pp+"\n"+pt
def detector(): user_input = request.args.get('user_input') print(user_input) result = detc.predict(user_input) if result == 1: resposta = 'Cuidado! Esta notícia é provavelmente fake.' elif result == 0: resposta = 'Esta notícia parece verdadeira.' return render_template('result.html', result=resposta)
def explore(url_name, depth): root = SpiderTree() root.name = url_name root.type = predict(url_name) if depth > 0: l = get_linked_urls(url_name) root.children = [] for u in l: print u root.children.append(explore(u, depth-1)) else: root.children = [] return root
from detector import predict username = input("Enter the Username to verify: ") print(predict(username))