dnth commited on
Commit
8cc86f4
·
1 Parent(s): ddc45e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -35
app.py CHANGED
@@ -4,38 +4,46 @@ import requests
4
  from telegram import ChatAction
5
  import os
6
 
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()
 
 
 
 
 
 
 
 
 
4
  from telegram import ChatAction
5
  import os
6
 
7
+ from flask import Flask
8
+ app = Flask(__name__)
9
+
10
+ @app.route("/")
11
+ def index():
12
+ def get_gpt_response(text):
13
+ r = requests.post(
14
+ url="https://hf.space/embed/akhaliq/gpt-j-6B/+/api/predict/",
15
+ json={"data": [text]},
16
+ )
17
+ response = r.json()
18
+ return response["data"][0]
19
+
20
+
21
+ def hello(update: Update, context: CallbackContext) -> None:
22
+ intro_text = """
23
+ 🤖 Greetings human! \n
24
+ 🤗 I'm a bot hosted on Hugging Face Spaces. \n
25
+ 💪 I can query the GPT-J-6B model by Ahsen Khaliq at https://huggingface.co/spaces/akhaliq/gpt-j-6B.\n
26
+ ✉️ Send me a text and I shall respond!\n\n
27
+ ‼️ PS: Responses are not my own (everything's from GPT-J-6B). I'm not conscious (yet).
28
+ """
29
+ update.message.reply_text(intro_text)
30
+
31
+
32
+ def respond_to_user(update: Update, context: CallbackContext):
33
+ update.message.chat.send_action(action=ChatAction.TYPING)
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)