Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,47 +3,39 @@ from telegram.ext import Updater, CommandHandler, CallbackContext, MessageHandle
|
|
3 |
import requests
|
4 |
from telegram import ChatAction
|
5 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
response_text = get_gpt_response(update.message.text)
|
35 |
-
update.message.reply_text(response_text)
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
updater = Updater(os.environ['telegram_api_key'])
|
40 |
-
|
41 |
-
updater.dispatcher.add_handler(CommandHandler("start", hello))
|
42 |
-
|
43 |
-
updater.dispatcher.add_handler(MessageHandler(Filters.text & ~Filters.command, respond_to_user))
|
44 |
-
|
45 |
-
updater.start_polling()
|
46 |
-
updater.idle()
|
47 |
-
|
48 |
-
if __name__ == "__main__":
|
49 |
-
app.run(host="0.0.0.0", port=7860)
|
3 |
import requests
|
4 |
from telegram import ChatAction
|
5 |
import os
|
6 |
+
1
|
7 |
+
def get_gpt_response(text):
|
8 |
+
r = requests.post(
|
9 |
+
url="https://hf.space/embed/akhaliq/gpt-j-6B/+/api/predict/",
|
10 |
+
json={"data": [text]},
|
11 |
+
)
|
12 |
+
response = r.json()
|
13 |
+
return response["data"][0]
|
14 |
|
15 |
+
|
16 |
+
def hello(update: Update, context: CallbackContext) -> None:
|
17 |
+
intro_text = """
|
18 |
+
π€ Greetings human! \n
|
19 |
+
π€ I'm a bot hosted on Hugging Face Spaces. \n
|
20 |
+
πͺ I can query the GPT-J-6B model by Ahsen Khaliq at https://huggingface.co/spaces/akhaliq/gpt-j-6B.\n
|
21 |
+
βοΈ Send me a text and I shall respond!\n\n
|
22 |
+
βΌοΈ PS: Responses are not my own (everything's from GPT-J-6B). I'm not conscious (yet).
|
23 |
+
"""
|
24 |
+
update.message.reply_text(intro_text)
|
25 |
+
|
26 |
+
|
27 |
+
def respond_to_user(update: Update, context: CallbackContext):
|
28 |
+
update.message.chat.send_action(action=ChatAction.TYPING)
|
29 |
+
response_text = get_gpt_response(update.message.text)
|
30 |
+
update.message.reply_text(response_text)
|
31 |
+
|
32 |
+
|
33 |
+
|
34 |
+
updater = Updater(os.environ['telegram_api_key'])
|
35 |
+
|
36 |
+
updater.dispatcher.add_handler(CommandHandler("start", hello))
|
37 |
+
|
38 |
+
updater.dispatcher.add_handler(MessageHandler(Filters.text & ~Filters.command, respond_to_user))
|
39 |
+
|
40 |
+
updater.start_polling()
|
41 |
+
updater.idle()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|