ubix commited on
Commit
8905861
·
1 Parent(s): e325d40

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +35 -0
  2. requirements.txt +2 -0
app.py CHANGED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from telegram import Update
2
+ from telegram.ext import Updater, CommandHandler, CallbackContext, MessageHandler, Filters
3
+ import requests
4
+ from telegram import ChatAction
5
+ import os
6
+
7
+ def hello(update: Update, context: CallbackContext) -> None:
8
+ intro_text = """
9
+ 🤖 Greetings human! \n
10
+ 🤗 I'm a bot hosted on Hugging Face Spaces. \n
11
+ 🦾 I can query the mighty GPT-J-6B model and send you a response here. Try me.\n
12
+ ✉️ Send me a text to start and I shall generate a response to complete your text!\n\n
13
+ ‼️ PS: Responses are not my own (everything's from GPT-J-6B). I'm not conscious (yet).\n
14
+ Blog post: https://dicksonneoh.com/portfolio/deploy_gpt_hf_models_on_telegram/
15
+ """
16
+ update.message.reply_text(intro_text)
17
+
18
+ def get_gpt_response(text):
19
+ r = requests.post(
20
+ url="https://hf.space/embed/dnth/gpt-j-6B/+/api/predict/",
21
+ json={"data": [text]},
22
+ )
23
+ response = r.json()
24
+ return response["data"][0]
25
+
26
+ def respond_to_user(update: Update, context: CallbackContext):
27
+ update.message.chat.send_action(action=ChatAction.TYPING)
28
+ response_text = get_gpt_response(update.message.text)
29
+ update.message.reply_text(response_text)
30
+
31
+ updater = Updater('5738478743:AAG9QbRtxWLoFIR9yVW7prnsRNsysaUeYDo')
32
+ updater.dispatcher.add_handler(CommandHandler("start", hello))
33
+ updater.dispatcher.add_handler(MessageHandler(Filters.text & ~Filters.command, respond_to_user))
34
+ updater.start_polling()
35
+ updater.idle()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ python-telegram-bot==13.11
2
+ requests==2.27.1