Spaces:
Runtime error
Runtime error
Commit
·
2e821b6
1
Parent(s):
6666f92
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,37 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import telegram
|
| 3 |
-
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
| 4 |
-
model = GPT2LMHeadModel.from_pretrained("gpt2-xl")
|
| 5 |
-
tokenizer = GPT2Tokenizer.from_pretrained("gpt2-xl")
|
| 6 |
-
def generate_response(input_text):
|
| 7 |
-
input_ids = tokenizer.encode(input_text, return_tensors="pt")
|
| 8 |
-
output = model.generate(input_ids, max_length=100, num_return_sequences=1)
|
| 9 |
-
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 10 |
-
return response
|
| 11 |
-
def handle_message(bot, update):
|
| 12 |
-
message = update.message
|
| 13 |
-
user_input = message.text
|
| 14 |
-
|
| 15 |
-
# Generate a response based on the user input
|
| 16 |
-
response = generate_response(user_input)
|
| 17 |
-
|
| 18 |
-
# Send the response back to the user
|
| 19 |
-
bot.send_message(chat_id=message.chat_id, text=response)
|
| 20 |
-
|
| 21 |
-
# Update the demo launch function to include the Telegram bot functionality
|
| 22 |
-
def launch_demo():
|
| 23 |
-
updater = telegram.Updater(TOKEN)
|
| 24 |
-
dispatcher = updater.dispatcher
|
| 25 |
-
|
| 26 |
-
# Register the message handler
|
| 27 |
-
dispatcher.add_handler(telegram.MessageHandler(telegram.Filters.text, handle_message))
|
| 28 |
-
|
| 29 |
-
# Start the bot
|
| 30 |
-
updater.start_polling()
|
| 31 |
-
|
| 32 |
-
# Launch the Gradio interface
|
| 33 |
-
demo.launch()
|
| 34 |
-
|
| 35 |
-
if __name__ == "__main__":
|
| 36 |
-
TOKEN = "6701619783:AAFE384ILY-KADTXQryB0mLqwh-Svwu2lyE" # Replace with your actual bot token
|
| 37 |
-
launch_demo()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|