Spaces:
Running
Running
| import gradio as gr | |
| import subprocess | |
| import os | |
| def swap_faces(source, target, is_video=False): | |
| output_path = "output.mp4" if is_video else "output.jpg" | |
| command = [ | |
| "python", "infer.py", | |
| "--source", source, | |
| "--target", target, | |
| "--output", output_path | |
| ] | |
| subprocess.run(command) | |
| return output_path | |
| iface = gr.Interface( | |
| fn=swap_faces, | |
| inputs=[ | |
| "file", # 允许上传文件(图片或视频) | |
| "file", # 目标换脸对象(图片) | |
| gr.Checkbox(label="Process as Video") # 选择是否处理视频 | |
| ], | |
| outputs="file", | |
| title="MagicFaceLab - Video & Image Swap", | |
| description="Upload an image or video and swap faces with the target face." | |
| ) | |
| iface.launch(server_name="0.0.0.0", server_port=7860) | |