YepoHz commited on
Commit
e1bb76a
·
verified ·
1 Parent(s): 6156262

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -6,7 +6,7 @@ import gradio as gr
6
  import uuid
7
  import subprocess
8
 
9
- # Directorios
10
  INPUT_DIR = "batch_images"
11
  OUTPUT_DIR = "batch_results"
12
  RESULTS_DIR = "comparaciones"
@@ -15,7 +15,7 @@ os.makedirs(OUTPUT_DIR, exist_ok=True)
15
  os.makedirs(RESULTS_DIR, exist_ok=True)
16
 
17
  def face_swap_batch(rb_img, lote_imgs):
18
- # Limpiar directorios
19
  shutil.rmtree(INPUT_DIR, ignore_errors=True)
20
  shutil.rmtree(OUTPUT_DIR, ignore_errors=True)
21
  shutil.rmtree(RESULTS_DIR, ignore_errors=True)
@@ -23,15 +23,16 @@ def face_swap_batch(rb_img, lote_imgs):
23
  os.makedirs(OUTPUT_DIR, exist_ok=True)
24
  os.makedirs(RESULTS_DIR, exist_ok=True)
25
 
26
- # Guardar imagen de rostro base
27
  rb_path = os.path.join(INPUT_DIR, "RB.jpg")
28
  rb_img.save(rb_path)
29
 
30
  # Guardar imágenes por lote
31
  img_paths = []
32
- for i, img in enumerate(lote_imgs):
33
  name = f"img_{i}.jpg"
34
  path = os.path.join(INPUT_DIR, name)
 
35
  img.save(path)
36
  img_paths.append(path)
37
 
@@ -48,7 +49,7 @@ def face_swap_batch(rb_img, lote_imgs):
48
  "--frame-processor", "face_swapper", "face_enhancer"
49
  ])
50
 
51
- # Crear comparaciones lado a lado
52
  resultados = []
53
  for path in img_paths:
54
  filename = os.path.basename(path)
@@ -64,7 +65,7 @@ def face_swap_batch(rb_img, lote_imgs):
64
  combinado.save(out_path)
65
  resultados.append(out_path)
66
 
67
- # Descarga
68
  if len(resultados) == 1:
69
  return resultados[0]
70
  else:
 
6
  import uuid
7
  import subprocess
8
 
9
+ # Crear carpetas necesarias
10
  INPUT_DIR = "batch_images"
11
  OUTPUT_DIR = "batch_results"
12
  RESULTS_DIR = "comparaciones"
 
15
  os.makedirs(RESULTS_DIR, exist_ok=True)
16
 
17
  def face_swap_batch(rb_img, lote_imgs):
18
+ # Limpiar carpetas anteriores
19
  shutil.rmtree(INPUT_DIR, ignore_errors=True)
20
  shutil.rmtree(OUTPUT_DIR, ignore_errors=True)
21
  shutil.rmtree(RESULTS_DIR, ignore_errors=True)
 
23
  os.makedirs(OUTPUT_DIR, exist_ok=True)
24
  os.makedirs(RESULTS_DIR, exist_ok=True)
25
 
26
+ # Guardar rostro base
27
  rb_path = os.path.join(INPUT_DIR, "RB.jpg")
28
  rb_img.save(rb_path)
29
 
30
  # Guardar imágenes por lote
31
  img_paths = []
32
+ for i, file in enumerate(lote_imgs):
33
  name = f"img_{i}.jpg"
34
  path = os.path.join(INPUT_DIR, name)
35
+ img = Image.open(file) # CORREGIDO: abrir archivo tipo NamedString
36
  img.save(path)
37
  img_paths.append(path)
38
 
 
49
  "--frame-processor", "face_swapper", "face_enhancer"
50
  ])
51
 
52
+ # Comparaciones lado a lado
53
  resultados = []
54
  for path in img_paths:
55
  filename = os.path.basename(path)
 
65
  combinado.save(out_path)
66
  resultados.append(out_path)
67
 
68
+ # Devolver resultado: zip o imagen única
69
  if len(resultados) == 1:
70
  return resultados[0]
71
  else: