Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,34 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|