File size: 949 Bytes
4b0fa9e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
import gradio as gr
import os
from facefusion import core

# Ensure environment variables are set properly
os.environ['OMP_NUM_THREADS'] = '1'

def face_swap(image1, image2):
    """Runs FaceFusion CLI with the provided images."""
    input_path1 = "input1.jpg"
    input_path2 = "input2.jpg"
    output_path = "output.jpg"

    # Save uploaded images
    image1.save(input_path1)
    image2.save(input_path2)

    # Run FaceFusion with command-line arguments
    os.system(f"facefusion -s {input_path1} -t {input_path2} -o {output_path}")

    return output_path

# Gradio interface
iface = gr.Interface(
    fn=face_swap,
    inputs=[
        gr.Image(type="pil", label="Source Face"),
        gr.Image(type="pil", label="Target Face")
    ],
    outputs=gr.Image(type="file", label="Swapped Face"),
    title="FaceFusion AI",
    description="Upload two images and let FaceFusion swap the faces."
)

if __name__ == "__main__":
    iface.launch()