|
import gradio as gr |
|
from telegram import Bot, Update |
|
from telegram.ext import CommandHandler, MessageHandler, Filters, Updater, CallbackContext |
|
|
|
|
|
bot = Bot(token="6516533220:AAEoq0ohv4xAraIw7lB7BZVHKyUg85wo3mI") |
|
|
|
|
|
def predict_text(text): |
|
|
|
prediction = "Your model's prediction: " + text |
|
return prediction |
|
|
|
iface = gr.Interface(fn=predict_text, inputs="text", outputs="text") |
|
|
|
|
|
def start(update: Update, context: CallbackContext): |
|
update.message.reply_text("Welcome to your bot! Send me text for predictions.") |
|
|
|
|
|
def handle_message(update: Update, context: CallbackContext): |
|
user_text = update.message.text |
|
prediction = predict_text(user_text) |
|
update.message.reply_text(prediction) |
|
|
|
|
|
updater = Updater(token="YOUR_TELEGRAM_BOT_TOKEN", use_context=True) |
|
dispatcher = updater.dispatcher |
|
|
|
|
|
dispatcher.add_handler(CommandHandler("start", start)) |
|
dispatcher.add_handler(MessageHandler(Filters.text & ~Filters.command, handle_message)) |
|
|
|
|
|
iface.launch(share=True) |
|
updater.start_polling() |
|
updater.idle() |
|
|