Spaces:
Runtime error
Runtime error
upload bot.py
Browse files
bot.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from telegram import Update
|
2 |
+
from telegram.ext import Updater, CommandHandler, CallbackContext, MessageHandler, Filters
|
3 |
+
from telegram import ChatAction
|
4 |
+
import os
|
5 |
+
from app import get_gpt_response
|
6 |
+
|
7 |
+
|
8 |
+
|
9 |
+
def hello(update: Update, context: CallbackContext) -> None:
|
10 |
+
intro_text = """
|
11 |
+
🤖 Greetings human! \n
|
12 |
+
🤗 I'm a bot hosted on Hugging Face Spaces. \n
|
13 |
+
🦾 I can query the mighty GPT-J-6B model and send you a response here. Try me.\n
|
14 |
+
✉️ Send me a text to start and I shall generate a response to complete your text!\n\n
|
15 |
+
‼️ PS: Responses are not my own (everything's from GPT-J-6B). I'm not conscious (yet).\n
|
16 |
+
"""
|
17 |
+
update.message.reply_text(intro_text)
|
18 |
+
|
19 |
+
|
20 |
+
|
21 |
+
|
22 |
+
def respond_to_user(update: Update, context: CallbackContext):
|
23 |
+
update.message.chat.send_action(action=ChatAction.TYPING)
|
24 |
+
response_text = get_gpt_response(update.message.text)
|
25 |
+
update.message.reply_text(response_text)
|
26 |
+
|
27 |
+
|
28 |
+
updater = Updater('5533872077:AAHwJ-zkpfjWc1sVb1BHRQFci2DczTaEVGI')
|
29 |
+
updater.dispatcher.add_handler(CommandHandler('start', hello))
|
30 |
+
updater.dispatcher.add_handler(MessageHandler(Filters.text & ~Filters.command, respond_to_user))
|
31 |
+
updater.start_polling()
|
32 |
+
updater.idle()
|
33 |
+
|