Update app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,35 @@
|
|
1 |
import gradio as gr
|
2 |
-
from telegram import
|
3 |
-
from telegram.ext import CommandHandler, MessageHandler, Filters, Updater, CallbackContext
|
4 |
|
5 |
-
#
|
6 |
-
|
7 |
|
8 |
-
#
|
9 |
-
def
|
10 |
-
|
11 |
-
|
12 |
-
return prediction
|
13 |
|
14 |
-
|
|
|
15 |
|
16 |
-
#
|
17 |
-
|
18 |
-
|
19 |
|
20 |
-
# Define a
|
21 |
-
def
|
22 |
-
|
23 |
-
prediction = predict_text(user_text)
|
24 |
-
update.message.reply_text(prediction)
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
29 |
|
30 |
-
|
31 |
-
dispatcher.add_handler(
|
32 |
-
dispatcher.add_handler(MessageHandler(Filters.text & ~Filters.command, handle_message))
|
33 |
|
34 |
-
# Start
|
35 |
-
iface.launch(share=True)
|
36 |
updater.start_polling()
|
37 |
updater.idle()
|
|
|
1 |
import gradio as gr
|
2 |
+
from telegram.ext import Updater, MessageHandler, Filters, CommandHandler, CallbackContext
|
|
|
3 |
|
4 |
+
# Define your Telegram bot token here
|
5 |
+
TELEGRAM_BOT_TOKEN = "6516533220:AAEoq0ohv4xAraIw7lB7BZVHKyUg85wo3mI"
|
6 |
|
7 |
+
# Create a Gradio interface
|
8 |
+
def greet(bot, update):
|
9 |
+
message = update.message.text
|
10 |
+
bot.send_message(chat_id=update.message.chat_id, text=f"Hello, you said: {message}")
|
|
|
11 |
|
12 |
+
# Create a Gradio interface
|
13 |
+
gr.Interface(fn=greet, inputs="text", outputs="text").launch(share=True)
|
14 |
|
15 |
+
# Set up the Telegram bot
|
16 |
+
updater = Updater(token=TELEGRAM_BOT_TOKEN, use_context=True)
|
17 |
+
dispatcher = updater.dispatcher
|
18 |
|
19 |
+
# Define a Telegram command handler
|
20 |
+
def start(update, context):
|
21 |
+
context.bot.send_message(chat_id=update.message.chat_id, text="Hello! I'm your Gradio Telegram Bot. Send me a message!")
|
|
|
|
|
22 |
|
23 |
+
start_handler = CommandHandler('start', start)
|
24 |
+
dispatcher.add_handler(start_handler)
|
25 |
+
|
26 |
+
# Define a Telegram message handler
|
27 |
+
def echo(update, context):
|
28 |
+
context.bot.send_message(chat_id=update.message.chat_id, text=update.message.text)
|
29 |
|
30 |
+
message_handler = MessageHandler(Filters.text & ~Filters.command, echo)
|
31 |
+
dispatcher.add_handler(message_handler)
|
|
|
32 |
|
33 |
+
# Start the Telegram bot
|
|
|
34 |
updater.start_polling()
|
35 |
updater.idle()
|