Spaces:
Running on Zero
Running on Zero
File size: 2,478 Bytes
8ce9e44 e50b2b4 8ce9e44 e50b2b4 32a4a8f 011d740 e50b2b4 011d740 e50b2b4 011d740 e50b2b4 011d740 e50b2b4 011d740 e50b2b4 75b7d18 32a4a8f 75b7d18 4bba595 8ce9e44 e50b2b4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | import asyncio
import threading
import logging
import gradio as gr
from main import app, start_web_server
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Compatibilidad ZeroGPU / Spaces
try:
import spaces
@spaces.GPU
def gpu_health_check(x):
return x
except Exception:
def gpu_health_check(x):
return x
_BOT_STARTED = False
_BOT_LOCK = threading.Lock()
def _start_bot_in_background():
global _BOT_STARTED
with _BOT_LOCK:
if _BOT_STARTED:
logger.info("El bot ya está en ejecución en otro hilo, omitiendo duplicación.")
return
_BOT_STARTED = True
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
async def _async_bot_runner():
try:
logger.info("Asignando loop y arrancando Pyrogram en memoria...")
app.loop = loop
await start_web_server()
await app.start()
logger.info("🟢 Bot de Telegram 'Twisted Audio' activo y respondiendo mensajes.")
try:
from pyrogram.types import BotCommand
await app.set_bot_commands([
BotCommand("start", "⚙️ Panel Principal"),
BotCommand("help", "❓ Ayuda e Instrucciones")
])
except Exception as e:
logger.warning(f"No se pudieron registrar comandos: {e}")
while True:
await asyncio.sleep(3600)
except Exception as e:
logger.error(f"Error al ejecutar el bot en segundo plano: {e}", exc_info=True)
loop.run_until_complete(_async_bot_runner())
# Iniciar el bot inmediatamente pero asegurando instancia única
bot_thread = threading.Thread(target=_start_bot_in_background, daemon=True)
bot_thread.start()
def check_status(user_input):
gpu_health_check(user_input)
return f"🟢 Bot 'Twisted Audio' activo 24/7 en Telegram. Recibido: {user_input}"
demo = gr.Interface(
fn=check_status,
inputs=gr.Textbox(label="Estado del Servidor", placeholder="Escribe algo para verificar..."),
outputs=gr.Textbox(label="Respuesta de confirmación"),
title="🎧 Twisted Audio",
description="### Bot de Telegram Activo 24/7 (Gradio Free SDK)\nEnvía tus videos al bot de Telegram para extraer su audio en formato MP3."
)
if __name__ == "__main__":
demo.launch(server_name="0.0.0.0", server_port=7860)
|