Spaces:
Paused
Paused
| import gradio as gr | |
| import subprocess | |
| import os | |
| def run_scripts(target, source, use_face_enhancer): | |
| if target is None or (not use_face_enhancer and source is None): | |
| return None | |
| target_path = target | |
| source_path = source | |
| target_extension = os.path.splitext(target_path)[-1] | |
| output_path1 = "output1" + target_extension | |
| output_path2 = "output2" + target_extension | |
| if not use_face_enhancer: | |
| cmd1 = [ | |
| "python3", "run.py", | |
| "-s", source_path, | |
| "-t", target_path, | |
| "-o", output_path1, | |
| "--frame-processor", "face_swapper" | |
| ] | |
| subprocess.run(cmd1, check=True) | |
| cmd2 = [ | |
| "python3", "run.py", | |
| "-t", target_path if use_face_enhancer else output_path1, | |
| "-o", output_path2, | |
| "--frame-processor", "face_enhancer" | |
| ] | |
| subprocess.run(cmd2, check=True) | |
| return output_path2 | |
| iface = gr.Interface( | |
| fn=run_scripts, | |
| inputs=[ | |
| gr.File(label="Target image/video", type="filepath"), | |
| gr.File(label="Source image", type="filepath"), | |
| gr.Checkbox(value=False, label="Use only Face Enhancer") | |
| ], | |
| outputs=gr.File(label="Output file"), | |
| title="Face swapper", | |
| description="Upload a target image/video and a source image to swap faces.", | |
| live=True | |
| ) | |
| iface.launch() |