Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,30 +3,35 @@ from gradio_client import Client, handle_file
|
|
| 3 |
|
| 4 |
def procesar_movimiento(imagen_ruta, video_ruta):
|
| 5 |
if not imagen_ruta or not video_ruta:
|
| 6 |
-
return None
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
return resultado
|
| 16 |
-
except Exception as e:
|
| 17 |
-
print(f"Error: {e}")
|
| 18 |
try:
|
| 19 |
-
|
| 20 |
-
client = Client("
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
with gr.Blocks() as demo:
|
| 32 |
gr.Markdown("# 🎬 Mi Clonador AI Móvil")
|
|
@@ -38,11 +43,13 @@ with gr.Blocks() as demo:
|
|
| 38 |
btn_generar = gr.Button("🪄 Generar Video", variant="primary")
|
| 39 |
with gr.TabItem("Resultado"):
|
| 40 |
output_vid = gr.Video(label="Tu video listo")
|
|
|
|
|
|
|
| 41 |
|
| 42 |
btn_generar.click(
|
| 43 |
fn=procesar_movimiento,
|
| 44 |
inputs=[input_img, input_vid],
|
| 45 |
-
outputs=output_vid
|
| 46 |
)
|
| 47 |
|
| 48 |
demo.launch(theme=gr.themes.Soft())
|
|
|
|
| 3 |
|
| 4 |
def procesar_movimiento(imagen_ruta, video_ruta):
|
| 5 |
if not imagen_ruta or not video_ruta:
|
| 6 |
+
return None, "Por favor, sube ambos archivos."
|
| 7 |
+
|
| 8 |
+
# Intentaremos con el servidor oficial optimizado
|
| 9 |
+
servidores = [
|
| 10 |
+
{"url": "KwaiVGI/LivePortrait", "img_param": "img_input", "vid_param": "driving_video"},
|
| 11 |
+
{"url": "fffiloni/LivePortrait-fast", "img_param": "img_input", "vid_param": "driving_video"}
|
| 12 |
+
]
|
| 13 |
+
|
| 14 |
+
for serv in servidores:
|
|
|
|
|
|
|
|
|
|
| 15 |
try:
|
| 16 |
+
print(f"Intentando con {serv['url']}...")
|
| 17 |
+
client = Client(serv["url"])
|
| 18 |
+
|
| 19 |
+
# Construimos los argumentos dinámicamente
|
| 20 |
+
args = {
|
| 21 |
+
serv["img_param"]: handle_file(imagen_ruta),
|
| 22 |
+
serv["vid_param"]: handle_file(video_ruta),
|
| 23 |
+
"api_name": "/predict"
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
resultado = client.predict(**args)
|
| 27 |
+
return resultado, "¡Video generado con éxito!"
|
| 28 |
+
|
| 29 |
+
except Exception as e:
|
| 30 |
+
error_msg = str(e)
|
| 31 |
+
print(f"Falló {serv['url']}: {error_msg}")
|
| 32 |
+
continue # Si falla uno, intenta con el siguiente
|
| 33 |
+
|
| 34 |
+
return None, f"Error del sistema: No se pudo conectar con los motores de IA. Detalles: {error_msg}"
|
| 35 |
|
| 36 |
with gr.Blocks() as demo:
|
| 37 |
gr.Markdown("# 🎬 Mi Clonador AI Móvil")
|
|
|
|
| 43 |
btn_generar = gr.Button("🪄 Generar Video", variant="primary")
|
| 44 |
with gr.TabItem("Resultado"):
|
| 45 |
output_vid = gr.Video(label="Tu video listo")
|
| 46 |
+
# Cuadro de texto para ver qué pasa en tiempo real
|
| 47 |
+
output_info = gr.Textbox(label="Estado del sistema", interactive=False)
|
| 48 |
|
| 49 |
btn_generar.click(
|
| 50 |
fn=procesar_movimiento,
|
| 51 |
inputs=[input_img, input_vid],
|
| 52 |
+
outputs=[output_vid, output_info]
|
| 53 |
)
|
| 54 |
|
| 55 |
demo.launch(theme=gr.themes.Soft())
|