Create main.py
Browse files
main.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
BOT_TOKEN = '12345:ABC-DEF1234ghIkl-zyx57W2v1u123ew11'
|
2 |
+
API_URL = "https://api-inference.huggingface.co/models/Meena/table-question-answering-tapas"
|
3 |
+
|
4 |
+
# Инициализация бота и диспетчера
|
5 |
+
bot = Bot(token=6381758679:AAE2B5GJxE0Ub8CLDqjVxrNCrPnnUPinP9gdp) Dispatcher(bot)
|
6 |
+
|
7 |
+
# Обработчик сообщений
|
8 |
+
@dp.message_handler()
|
9 |
+
async def message_handler(message: types.Message):
|
10 |
+
# Получаем текст вопроса пользователя
|
11 |
+
question = message.text
|
12 |
+
|
13 |
+
# Формируем JSON-запрос к API модели Meena
|
14 |
+
payload = {
|
15 |
+
"inputs": {
|
16 |
+
"query": question,
|
17 |
+
"table": {...} # Табличные данные (если есть)
|
18 |
+
}
|
19 |
+
}
|
20 |
+
|
21 |
+
# Делаем запрос к API и получаем ответ
|
22 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
23 |
+
answer = response.json()
|
24 |
+
|
25 |
+
# Отправляем ответ пользователю
|
26 |
+
await message.answer(answer['answer'])
|
27 |
+
|
28 |
+
# Запуск бота
|
29 |
+
executor.start_polling(dp, skip_updates=True)
|