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