YepoHz commited on
Commit
494f391
·
verified ·
1 Parent(s): d181fc7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -10
app.py CHANGED
@@ -12,7 +12,7 @@ OUTPUT_DIR = "batch_results"
12
  os.makedirs(INPUT_DIR, exist_ok=True)
13
  os.makedirs(OUTPUT_DIR, exist_ok=True)
14
 
15
- def face_swap_batch(rb_img, lote_imgs):
16
  # Limpiar carpetas anteriores
17
  shutil.rmtree(INPUT_DIR, ignore_errors=True)
18
  shutil.rmtree(OUTPUT_DIR, ignore_errors=True)
@@ -28,7 +28,7 @@ def face_swap_batch(rb_img, lote_imgs):
28
  for i, file in enumerate(lote_imgs):
29
  name = f"img_{i}.jpg"
30
  path = os.path.join(INPUT_DIR, name)
31
- img = Image.open(file) # NamedString → PIL
32
  img.save(path)
33
  img_paths.append(path)
34
 
@@ -45,7 +45,7 @@ def face_swap_batch(rb_img, lote_imgs):
45
  "--frame-processor", "face_swapper", "face_enhancer"
46
  ])
47
 
48
- # Recolectar resultados finales
49
  resultados = []
50
  for path in img_paths:
51
  filename = os.path.basename(path)
@@ -53,24 +53,25 @@ def face_swap_batch(rb_img, lote_imgs):
53
  if os.path.exists(generado_path):
54
  resultados.append(generado_path)
55
 
56
- # Entregar como imagen o ZIP
57
- if len(resultados) == 1:
58
- return resultados[0]
59
- else:
60
  zip_path = f"resultados_{uuid.uuid4().hex[:6]}.zip"
61
  with zipfile.ZipFile(zip_path, 'w') as zipf:
62
  for file in resultados:
63
  zipf.write(file, os.path.basename(file))
64
  return zip_path
 
 
65
 
66
  # Interfaz Gradio
67
  gr.Interface(
68
  fn=face_swap_batch,
69
  inputs=[
70
  gr.Image(label="🧠 Rostro base", type="pil"),
71
- gr.File(label="🖼️ Imágenes por lote", file_types=["image"], file_count="multiple")
 
72
  ],
73
- outputs=gr.File(label="📦 Descargar resultado"),
74
  title="Deep Fake Lote - Yepo Hz",
75
- description="Sube una imagen de rostro base y varias imágenes objetivo. El sistema aplicará el cambio de rostro en lote y devolverá imágenes procesadas (mejoradas)."
76
  ).launch()
 
12
  os.makedirs(INPUT_DIR, exist_ok=True)
13
  os.makedirs(OUTPUT_DIR, exist_ok=True)
14
 
15
+ def face_swap_batch(rb_img, lote_imgs, usar_zip):
16
  # Limpiar carpetas anteriores
17
  shutil.rmtree(INPUT_DIR, ignore_errors=True)
18
  shutil.rmtree(OUTPUT_DIR, ignore_errors=True)
 
28
  for i, file in enumerate(lote_imgs):
29
  name = f"img_{i}.jpg"
30
  path = os.path.join(INPUT_DIR, name)
31
+ img = Image.open(file)
32
  img.save(path)
33
  img_paths.append(path)
34
 
 
45
  "--frame-processor", "face_swapper", "face_enhancer"
46
  ])
47
 
48
+ # Recolectar resultados
49
  resultados = []
50
  for path in img_paths:
51
  filename = os.path.basename(path)
 
53
  if os.path.exists(generado_path):
54
  resultados.append(generado_path)
55
 
56
+ # ZIP opcional
57
+ if usar_zip or len(resultados) > 1:
 
 
58
  zip_path = f"resultados_{uuid.uuid4().hex[:6]}.zip"
59
  with zipfile.ZipFile(zip_path, 'w') as zipf:
60
  for file in resultados:
61
  zipf.write(file, os.path.basename(file))
62
  return zip_path
63
+ else:
64
+ return resultados[0]
65
 
66
  # Interfaz Gradio
67
  gr.Interface(
68
  fn=face_swap_batch,
69
  inputs=[
70
  gr.Image(label="🧠 Rostro base", type="pil"),
71
+ gr.File(label="🖼️ Imágenes por lote", file_types=["image"], file_count="multiple"),
72
+ gr.Checkbox(label="📦 Descargar como ZIP", value=False)
73
  ],
74
+ outputs=gr.File(label=" Resultado procesado"),
75
  title="Deep Fake Lote - Yepo Hz",
76
+ description="Sube una imagen de rostro base y varias imágenes objetivo. El sistema aplicará el cambio de rostro. Puedes elegir si descargar como ZIP o imagen directa."
77
  ).launch()