""" app.py β€” FastAPI + CompresUltra Bot DiseΓ±ado para Hugging Face Spaces (o cualquier servidor con uvicorn). El bot Pyrogram y FastAPI comparten el MISMO event loop asyncio. Esto evita conflictos con asyncio y garantiza que el bot funcione. Arrancar con: uvicorn app:app --host 0.0.0.0 --port 7860 """ import asyncio import logging from contextlib import asynccontextmanager from fastapi import FastAPI from fastapi.responses import HTMLResponse # Importamos las funciones de inicio/parada del bot from main import start_bot, stop_bot logger = logging.getLogger(__name__) @asynccontextmanager async def lifespan(application: FastAPI): """ Ciclo de vida de FastAPI: - Al arrancar: inicia el bot en el mismo event loop. - Al apagar: detiene el bot limpiamente. """ logger.info("πŸ”§ Arrancando CompresUltra Bot...") await start_bot() # ← awaitable, mismo event loop logger.info("βœ… Bot activo y FastAPI listo.") yield # ← FastAPI sirve peticiones aquΓ­ logger.info("πŸ›‘ Apagando bot...") await stop_bot() app = FastAPI( title="CompresUltra Bot", description="Bot de Telegram para comprimir videos con FFmpeg y colas por plan", version="6.0", lifespan=lifespan, ) @app.get("/", response_class=HTMLResponse) async def root(): return """ CompresUltra Bot

πŸ€– CompresUltra Bot

● Online

Bot de Telegram para comprimir videos con FFmpeg y colas por plan

⚑ Motor: libx265 | πŸ—„οΈ DB: Supabase / Postgres


πŸ‘¨β€πŸ’» Desarrollador

""" @app.get("/health") async def health(): return {"status": "ok", "bot": "CompresUltra Bot V.6 Ultra Supabase"} @app.get("/ping") async def ping(): return {"pong": True}