dnth commited on
Commit
bc7c9d0
β€’
1 Parent(s): b5eea57

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -15
app.py CHANGED
@@ -4,15 +4,6 @@ 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/dnth/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
@@ -25,19 +16,21 @@ Blog post: https://dicksonneoh.com/portfolio/deploy_gpt_hf_models_on_telegram/
25
  """
26
  update.message.reply_text(intro_text)
27
 
 
 
 
 
 
 
 
28
 
29
  def respond_to_user(update: Update, context: CallbackContext):
30
  update.message.chat.send_action(action=ChatAction.TYPING)
31
  response_text = get_gpt_response(update.message.text)
32
  update.message.reply_text(response_text)
33
 
34
-
35
-
36
- updater = Updater(os.environ['telegram_api_key'])
37
-
38
  updater.dispatcher.add_handler(CommandHandler("start", hello))
39
-
40
  updater.dispatcher.add_handler(MessageHandler(Filters.text & ~Filters.command, respond_to_user))
41
-
42
  updater.start_polling()
43
  updater.idle()
 
4
  from telegram import ChatAction
5
  import os
6
 
 
 
 
 
 
 
 
 
 
7
  def hello(update: Update, context: CallbackContext) -> None:
8
  intro_text = """
9
  πŸ€– Greetings human! \n
 
16
  """
17
  update.message.reply_text(intro_text)
18
 
19
+ def get_gpt_response(text):
20
+ r = requests.post(
21
+ url="https://hf.space/embed/dnth/gpt-j-6B/+/api/predict/",
22
+ json={"data": [text]},
23
+ )
24
+ response = r.json()
25
+ return response["data"][0]
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
+ updater = Updater(os.environ['telegram_token'])
 
 
 
33
  updater.dispatcher.add_handler(CommandHandler("start", hello))
 
34
  updater.dispatcher.add_handler(MessageHandler(Filters.text & ~Filters.command, respond_to_user))
 
35
  updater.start_polling()
36
  updater.idle()