Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,8 @@ import gradio as gr
|
|
| 2 |
import subprocess
|
| 3 |
import shutil
|
| 4 |
import os
|
|
|
|
|
|
|
| 5 |
|
| 6 |
def run_scripts(target, source, use_face_enhancer):
|
| 7 |
if target is None or (not use_face_enhancer and source is None):
|
|
@@ -12,20 +14,21 @@ def run_scripts(target, source, use_face_enhancer):
|
|
| 12 |
output_path2 = "output2" + target_extension
|
| 13 |
|
| 14 |
if not use_face_enhancer:
|
| 15 |
-
# Run both scripts
|
| 16 |
cmd1 = ["python3", "run.py", "-s", source.name, "-t", target.name, "-o", output_path1, "--frame-processor", "face_swapper"]
|
| 17 |
subprocess.run(cmd1)
|
| 18 |
|
| 19 |
-
# Run the second script
|
| 20 |
cmd2 = ["python3", "run.py", "-t", target.name if use_face_enhancer else output_path1, "-o", output_path2, "--frame-processor", "face_enhancer"]
|
| 21 |
subprocess.run(cmd2)
|
| 22 |
|
| 23 |
if not use_face_enhancer:
|
| 24 |
os.remove(source.name)
|
| 25 |
os.remove(target.name)
|
| 26 |
-
|
| 27 |
-
#
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
iface = gr.Interface(
|
| 31 |
fn=run_scripts,
|
|
@@ -34,7 +37,7 @@ iface = gr.Interface(
|
|
| 34 |
"file",
|
| 35 |
gr.inputs.Checkbox(default=False, label="Use only Face Enhancer")
|
| 36 |
],
|
| 37 |
-
outputs="
|
| 38 |
title="Face swapper",
|
| 39 |
description="Upload a target image/video and a source image to swap faces.",
|
| 40 |
live=True
|
|
|
|
| 2 |
import subprocess
|
| 3 |
import shutil
|
| 4 |
import os
|
| 5 |
+
from PIL import Image
|
| 6 |
+
import numpy as np
|
| 7 |
|
| 8 |
def run_scripts(target, source, use_face_enhancer):
|
| 9 |
if target is None or (not use_face_enhancer and source is None):
|
|
|
|
| 14 |
output_path2 = "output2" + target_extension
|
| 15 |
|
| 16 |
if not use_face_enhancer:
|
|
|
|
| 17 |
cmd1 = ["python3", "run.py", "-s", source.name, "-t", target.name, "-o", output_path1, "--frame-processor", "face_swapper"]
|
| 18 |
subprocess.run(cmd1)
|
| 19 |
|
|
|
|
| 20 |
cmd2 = ["python3", "run.py", "-t", target.name if use_face_enhancer else output_path1, "-o", output_path2, "--frame-processor", "face_enhancer"]
|
| 21 |
subprocess.run(cmd2)
|
| 22 |
|
| 23 |
if not use_face_enhancer:
|
| 24 |
os.remove(source.name)
|
| 25 |
os.remove(target.name)
|
| 26 |
+
|
| 27 |
+
# Open the image with PIL and convert to NumPy array
|
| 28 |
+
with Image.open(output_path2) as img:
|
| 29 |
+
img_array = np.array(img)
|
| 30 |
+
|
| 31 |
+
return img_array
|
| 32 |
|
| 33 |
iface = gr.Interface(
|
| 34 |
fn=run_scripts,
|
|
|
|
| 37 |
"file",
|
| 38 |
gr.inputs.Checkbox(default=False, label="Use only Face Enhancer")
|
| 39 |
],
|
| 40 |
+
outputs="image", # Change the output type to image
|
| 41 |
title="Face swapper",
|
| 42 |
description="Upload a target image/video and a source image to swap faces.",
|
| 43 |
live=True
|