File size: 808 Bytes
657f39a
cc9114e
c79a705
cc9114e
c79a705
 
 
cc9114e
 
c79a705
 
 
cc9114e
c79a705
cc9114e
c79a705
cc9114e
 
 
c79a705
 
 
 
 
 
 
 
cc9114e
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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)