import os import telebot import gradio as gr from gradio_client import Client import threading BOT_TOKEN = os.environ.get("BOT_TOKEN") bot = telebot.TeleBot(BOT_TOKEN) user_data = {} @bot.message_handler(commands=['start']) def send_welcome(message): bot.reply_to(message, "স্বাগতম! আমাকে একটি ছবি দিন, তারপর এনিমেশন প্রম্পট দিন।") @bot.message_handler(content_types=['photo']) def handle_photo(message): chat_id = message.chat.id file_id = message.photo[-1].file_id file_info = bot.get_file(file_id) downloaded_file = bot.download_file(file_info.file_path) image_path = f"image_{chat_id}.jpg" with open(image_path, 'wb') as new_file: new_file.write(downloaded_file) user_data[chat_id] = {'image': image_path} bot.reply_to(message, "ছবি পেয়েছি! এবার মোশন প্রম্পটটি লিখে দিন।") @bot.message_handler(func=lambda message: True) def handle_prompt(message): chat_id = message.chat.id if chat_id in user_data and 'image' in user_data[chat_id]: prompt = message.text bot.reply_to(message, "ভিডিও তৈরি হচ্ছে... দয়া করে অপেক্ষা করুন।") try: # আমরা এখানে Client কল করার সময় সার্ভারকে একটু সময় দিচ্ছি client = Client("TencentARC/MotionCtrl") result_video_path = client.predict( user_data[chat_id]['image'], prompt, api_name="/predict" ) video = open(result_video_path, 'rb') bot.send_video(chat_id, video) del user_data[chat_id] except Exception as e: # এবার বট সার্ভারের আসল এররটা আপনাকে সেন্ড করবে bot.reply_to(message, f"❌ সার্ভার ফেইল করেছে! আসল কারণ হলো:\n\n{str(e)}") else: bot.reply_to(message, "দয়া করে আগে একটি ছবি দিন।") def run_bot(): bot.polling(none_stop=True) threading.Thread(target=run_bot, daemon=True).start() with gr.Blocks() as demo: gr.Markdown("# 🤖 Bot is Online") demo.launch()