This repository has been archived by the owner on Oct 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
58 lines (42 loc) · 1.6 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import time
import sys
sys.path.insert(1, '/path/to/application/app/folder')
import torch
from transformers import BertForQuestionAnswering
import telebot
from telebot import types
from utils.inference import answer_question
TELEBOT_TOKEN = '' # input token here
bot = telebot.TeleBot(TELEBOT_TOKEN)
bert_abstract = ''
question = ''
@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
bot.send_message(message.chat.id, 'Hello! Enter your text')
bot.register_next_step_handler(message, process_text)
def process_text(message):
global bert_abstract
markup = types.ReplyKeyboardRemove(selective=False)
bot.send_message(message.chat.id, 'Enter your question')
bert_abstract = message.text
bot.register_next_step_handler(message, answer)
def answer(message):
global question
question = message.text
markup = types.ReplyKeyboardRemove(selective=False)
bot.send_message(message.chat.id, 'Analyzing...')
markup = types.InlineKeyboardMarkup(row_width=2)
item1 = types.InlineKeyboardButton("Change text", callback_data='good')
item2 = types.InlineKeyboardButton("Enter another question", callback_data='bad')
markup.add(item1, item2)
bot.send_message(message.chat.id, answer_question(question, bert_abstract))
do_again(message)
def do_again(message):
global question
bot.send_message(message.chat.id, 'Done, try another question)')
bot.register_next_step_handler(message, answer)
while True:
try:
bot.polling(none_stop=True)
except:
time.sleep(5)