Spaces:
Paused
Paused
Upload app (1).py
Browse files- app (1).py +58 -0
app (1).py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import os
|
| 4 |
+
import shutil
|
| 5 |
+
import subprocess
|
| 6 |
+
from PIL import Image
|
| 7 |
+
|
| 8 |
+
# === Descarga y configuraci贸n de Roop ===
|
| 9 |
+
if not os.path.exists("roop"):
|
| 10 |
+
subprocess.run(["git", "clone", "https://github.com/s0md3v/roop.git"])
|
| 11 |
+
os.chdir("roop")
|
| 12 |
+
|
| 13 |
+
subprocess.run(["pip", "uninstall", "-y", "jax", "jaxlib", "numpy", "tensorflow"])
|
| 14 |
+
subprocess.run(["pip", "install", "numpy==1.23.5", "jax==0.4.13", "jaxlib==0.4.13", "tensorflow==2.12.0"])
|
| 15 |
+
subprocess.run(["pip", "install", "-r", "requirements.txt"])
|
| 16 |
+
|
| 17 |
+
os.chdir("..")
|
| 18 |
+
|
| 19 |
+
def procesar_lote(img_rostro, imgs_objetivo):
|
| 20 |
+
input_dir = "roop/batch_input"
|
| 21 |
+
output_dir = "roop/batch_output"
|
| 22 |
+
|
| 23 |
+
shutil.rmtree(input_dir, ignore_errors=True)
|
| 24 |
+
shutil.rmtree(output_dir, ignore_errors=True)
|
| 25 |
+
os.makedirs(input_dir, exist_ok=True)
|
| 26 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 27 |
+
|
| 28 |
+
rostro_path = os.path.join("roop", "RB.jpg")
|
| 29 |
+
img_rostro.save(rostro_path)
|
| 30 |
+
|
| 31 |
+
for img_file in imgs_objetivo:
|
| 32 |
+
image = Image.open(img_file)
|
| 33 |
+
image.save(os.path.join(input_dir, os.path.basename(img_file)))
|
| 34 |
+
|
| 35 |
+
comando = [
|
| 36 |
+
"python", "roop/run.py",
|
| 37 |
+
"--source_face", rostro_path,
|
| 38 |
+
"--target_folder", input_dir,
|
| 39 |
+
"--output_folder", output_dir,
|
| 40 |
+
"--frame-processor", "face_swapper"
|
| 41 |
+
]
|
| 42 |
+
subprocess.run(comando)
|
| 43 |
+
|
| 44 |
+
zip_path = "roop/resultado.zip"
|
| 45 |
+
shutil.make_archive(zip_path.replace(".zip", ""), 'zip', output_dir)
|
| 46 |
+
|
| 47 |
+
return zip_path
|
| 48 |
+
|
| 49 |
+
gr.Interface(
|
| 50 |
+
fn=procesar_lote,
|
| 51 |
+
inputs=[
|
| 52 |
+
gr.Image(label="Rostro base (RB.jpg)", type="pil"),
|
| 53 |
+
gr.File(file_types=["image"], label="Im谩genes a procesar", file_count="multiple")
|
| 54 |
+
],
|
| 55 |
+
outputs=gr.File(label="Descargar resultados ZIP"),
|
| 56 |
+
title="Intercambio de rostros por lote con Roop",
|
| 57 |
+
description="Sube una imagen de rostro base y varias im谩genes objetivo. El sistema procesar谩 todas y devolver谩 un ZIP con los resultados.",
|
| 58 |
+
).launch()
|