Emkay commited on
Commit
85e164c
·
1 Parent(s): f77bb6d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -15
app.py CHANGED
@@ -1,19 +1,34 @@
1
- import gradio as gr
 
 
 
 
2
 
3
- title = "GPT-J-6B"
 
 
 
 
 
 
 
 
4
 
5
- description = "ORIENT TELECOMS (the Company), incorporated in UK on the 26th Feb 2016, \
6
- is a Managed Telecommunications Service Provider (MSP) with wide range of Telecom Services in its portfolio."
 
 
 
 
 
7
 
 
 
 
 
8
 
9
- examples = [
10
- ['The Twin tower is in Malaysia and Its Height is 452 meters,'],
11
- ["The Moon's orbit around Earth has"],
12
- ["The smooth Borealis basin in the Northern Hemisphere covers 40%"]
13
- ]
14
-
15
- gr.Interface.load("huggingface/EleutherAI/gpt-j-6B",
16
- inputs=gr.inputs.Textbox(lines=5, label="Input Text"),
17
- title=title,description=description,
18
- examples=examples,
19
- enable_queue=True).launch()
 
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
+ """
15
+ update.message.reply_text(intro_text)
16
 
17
+ def get_gpt_response(text):
18
+ r = requests.post(
19
+ url="https://hf.space/Emkay/Asrix_Botgpt-j-6B/+/api/predict/",
20
+ json={"data": [text]},
21
+ )
22
+ response = r.json()
23
+ return response["data"][0]
24
 
25
+ def respond_to_user(update: Update, context: CallbackContext):
26
+ update.message.chat.send_action(action=ChatAction.TYPING)
27
+ response_text = get_gpt_response(update.message.text)
28
+ update.message.reply_text(response_text)
29
 
30
+ updater = Updater(os.environ['telegram_token'])
31
+ updater.dispatcher.add_handler(CommandHandler("start", hello))
32
+ updater.dispatcher.add_handler(MessageHandler(Filters.text & ~Filters.command, respond_to_user))
33
+ updater.start_polling()
34
+ updater.idle()