""" MTXtyle Bot - Hugging Face Spaces Entry Point (Gradio SDK) Runs the Telegram bot in a background thread and provides a Gradio status interface. """ import threading import os import time import gradio as gr bot_status = "⏳ Ishga tushirilmoqda..." def run_bot(): global bot_status token = os.getenv("BOT_TOKEN") if not token: bot_status = "❌ BOT_TOKEN topilmadi! Settings -> Secrets ga qo'shing." return # Import and run bot directly in thread try: bot_status = "🔄 Bot yuklanmoqda..." time.sleep(3) # Import bot module import asyncio from bot import main as bot_main bot_status = "✅ Bot ishlayapti!" # Run the bot bot_main() except Exception as e: bot_status = f"❌ Xato: {str(e)[:200]}" def get_status(): return bot_status # Start bot in background bot_thread = threading.Thread(target=run_bot, daemon=True) bot_thread.start() # Gradio Interface with gr.Blocks(title="MTXtyle Bot") as demo: gr.Markdown("# 🤖 MTXtyle Telegram Bot") gr.Markdown("Kiyim va aksessuarlar do'koni uchun Telegram bot") status_box = gr.Textbox(label="Bot Holati", value=bot_status, interactive=False) refresh_btn = gr.Button("🔄 Yangilash") refresh_btn.click(fn=get_status, outputs=[status_box]) demo.load(fn=get_status, outputs=[status_box]) demo.launch(server_name="0.0.0.0", server_port=7860)