CamiloBz commited on
Commit
c5c4ec4
·
verified ·
1 Parent(s): 94a3b7e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -24
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
- try:
8
- # Usamos un puente espejo alternativo que no pide login
9
- client = Client("prodia/Fast-LivePortrait")
10
- resultado = client.predict(
11
- input_image=handle_file(imagen_ruta),
12
- driving_video=handle_file(video_ruta),
13
- api_name="/predict"
14
- )
15
- return resultado
16
- except Exception as e:
17
- print(f"Error: {e}")
18
  try:
19
- # Si el anterior falla, intenta con este segundo respaldo automáticamente
20
- client = Client("fffiloni/LivePortrait-fast")
21
- resultado = client.predict(
22
- img_input=handle_file(imagen_ruta),
23
- driving_video=handle_file(video_ruta),
24
- api_name="/predict"
25
- )
26
- return resultado
27
- except Exception as e2:
28
- print(f"Error 2: {e2}")
29
- return None
 
 
 
 
 
 
 
 
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())