Spaces:
Running on Zero
Running on Zero
Upload 40 files
Browse files
app.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
import asyncio
|
| 2 |
-
import threading
|
| 3 |
import logging
|
| 4 |
import gradio as gr
|
| 5 |
from main import app, start_web_server
|
|
@@ -7,7 +6,7 @@ from main import app, start_web_server
|
|
| 7 |
logging.basicConfig(level=logging.INFO)
|
| 8 |
logger = logging.getLogger(__name__)
|
| 9 |
|
| 10 |
-
#
|
| 11 |
try:
|
| 12 |
import spaces
|
| 13 |
@spaces.GPU
|
|
@@ -17,39 +16,11 @@ except Exception:
|
|
| 17 |
def gpu_health_check(x):
|
| 18 |
return x
|
| 19 |
|
| 20 |
-
async def run_bot_async():
|
| 21 |
-
try:
|
| 22 |
-
logger.info("Iniciando servidor interno y cliente Pyrogram...")
|
| 23 |
-
await start_web_server()
|
| 24 |
-
await app.start()
|
| 25 |
-
logger.info("🟢 Bot de Telegram 'Twisted Audio' iniciado con éxito.")
|
| 26 |
-
|
| 27 |
-
try:
|
| 28 |
-
from pyrogram.types import BotCommand
|
| 29 |
-
await app.set_bot_commands([
|
| 30 |
-
BotCommand("start", "⚙️ Panel Principal"),
|
| 31 |
-
BotCommand("help", "❓ Ayuda e Instrucciones")
|
| 32 |
-
])
|
| 33 |
-
except Exception as e:
|
| 34 |
-
logger.warning(f"No se pudieron configurar los comandos del bot: {e}")
|
| 35 |
-
|
| 36 |
-
while True:
|
| 37 |
-
await asyncio.sleep(3600)
|
| 38 |
-
except Exception as e:
|
| 39 |
-
logger.error(f"Error en el bot de Telegram: {e}")
|
| 40 |
-
|
| 41 |
-
def start_bot_thread():
|
| 42 |
-
loop = asyncio.new_event_loop()
|
| 43 |
-
asyncio.set_event_loop(loop)
|
| 44 |
-
loop.run_until_complete(run_bot_async())
|
| 45 |
-
|
| 46 |
-
# Iniciar el bot de Telegram en segundo plano
|
| 47 |
-
threading.Thread(target=start_bot_thread, daemon=True).start()
|
| 48 |
-
|
| 49 |
def check_status(user_input):
|
| 50 |
gpu_health_check(user_input)
|
| 51 |
return f"🟢 Bot 'Twisted Audio' activo 24/7 en Telegram. Recibido: {user_input}"
|
| 52 |
|
|
|
|
| 53 |
demo = gr.Interface(
|
| 54 |
fn=check_status,
|
| 55 |
inputs=gr.Textbox(label="Estado del Servidor", placeholder="Escribe algo para verificar..."),
|
|
@@ -58,5 +29,28 @@ demo = gr.Interface(
|
|
| 58 |
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."
|
| 59 |
)
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
if __name__ == "__main__":
|
| 62 |
-
|
|
|
|
| 1 |
import asyncio
|
|
|
|
| 2 |
import logging
|
| 3 |
import gradio as gr
|
| 4 |
from main import app, start_web_server
|
|
|
|
| 6 |
logging.basicConfig(level=logging.INFO)
|
| 7 |
logger = logging.getLogger(__name__)
|
| 8 |
|
| 9 |
+
# Compatibilidad con Hugging Face ZeroGPU / Spaces
|
| 10 |
try:
|
| 11 |
import spaces
|
| 12 |
@spaces.GPU
|
|
|
|
| 16 |
def gpu_health_check(x):
|
| 17 |
return x
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
def check_status(user_input):
|
| 20 |
gpu_health_check(user_input)
|
| 21 |
return f"🟢 Bot 'Twisted Audio' activo 24/7 en Telegram. Recibido: {user_input}"
|
| 22 |
|
| 23 |
+
# Interfaz Gradio
|
| 24 |
demo = gr.Interface(
|
| 25 |
fn=check_status,
|
| 26 |
inputs=gr.Textbox(label="Estado del Servidor", placeholder="Escribe algo para verificar..."),
|
|
|
|
| 29 |
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."
|
| 30 |
)
|
| 31 |
|
| 32 |
+
async def run_all():
|
| 33 |
+
# 1. Iniciar Gradio en modo no bloqueante
|
| 34 |
+
logger.info("Iniciando interfaz Gradio...")
|
| 35 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, prevent_thread_lock=True)
|
| 36 |
+
|
| 37 |
+
# 2. Iniciar servidor web secundario y cliente Pyrogram en el event loop principal
|
| 38 |
+
logger.info("Iniciando servidor interno y cliente Pyrogram...")
|
| 39 |
+
await start_web_server()
|
| 40 |
+
await app.start()
|
| 41 |
+
logger.info("🟢 Bot de Telegram 'Twisted Audio' iniciado con éxito.")
|
| 42 |
+
|
| 43 |
+
try:
|
| 44 |
+
from pyrogram.types import BotCommand
|
| 45 |
+
await app.set_bot_commands([
|
| 46 |
+
BotCommand("start", "⚙️ Panel Principal"),
|
| 47 |
+
BotCommand("help", "❓ Ayuda e Instrucciones")
|
| 48 |
+
])
|
| 49 |
+
except Exception as e:
|
| 50 |
+
logger.warning(f"No se pudieron configurar los comandos del bot: {e}")
|
| 51 |
+
|
| 52 |
+
from pyrogram import idle
|
| 53 |
+
await idle()
|
| 54 |
+
|
| 55 |
if __name__ == "__main__":
|
| 56 |
+
asyncio.run(run_all())
|