Apex-X commited on
Commit
ac0f7a4
1 Parent(s): 803cbcc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -26
app.py CHANGED
@@ -1,37 +1,35 @@
1
  import gradio as gr
2
- from telegram import Bot, Update
3
- from telegram.ext import CommandHandler, MessageHandler, Filters, Updater, CallbackContext
4
 
5
- # Initialize your Telegram bot
6
- bot = Bot(token="6516533220:AAEoq0ohv4xAraIw7lB7BZVHKyUg85wo3mI")
7
 
8
- # Define a Gradio interface for your machine learning model
9
- def predict_text(text):
10
- # Replace this with your model's prediction logic
11
- prediction = "Your model's prediction: " + text
12
- return prediction
13
 
14
- iface = gr.Interface(fn=predict_text, inputs="text", outputs="text")
 
15
 
16
- # Define a command handler for the Telegram bot
17
- def start(update: Update, context: CallbackContext):
18
- update.message.reply_text("Welcome to your bot! Send me text for predictions.")
19
 
20
- # Define a message handler for the Telegram bot
21
- def handle_message(update: Update, context: CallbackContext):
22
- user_text = update.message.text
23
- prediction = predict_text(user_text)
24
- update.message.reply_text(prediction)
25
 
26
- # Initialize the Telegram bot updater
27
- updater = Updater(token="YOUR_TELEGRAM_BOT_TOKEN", use_context=True)
28
- dispatcher = updater.dispatcher
 
 
 
29
 
30
- # Register command and message handlers
31
- dispatcher.add_handler(CommandHandler("start", start))
32
- dispatcher.add_handler(MessageHandler(Filters.text & ~Filters.command, handle_message))
33
 
34
- # Start both the Gradio interface and the Telegram bot
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()