Spaces:
Paused
Paused
File size: 1,259 Bytes
130daed 2e5f4b8 130daed 5eacace 130daed 2e5f4b8 130daed 2e5f4b8 130daed 2e5f4b8 130daed 2e5f4b8 130daed 2e5f4b8 130daed 2e5f4b8 130daed 2e5f4b8 130daed | 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 38 39 40 41 42 43 44 45 46 47 | import os
import uuid
import subprocess
import gradio as gr
OUTPUT_DIR = "/tmp/outputs"
os.makedirs(OUTPUT_DIR, exist_ok=True)
def swap_faces(source_image, target_video):
uid = uuid.uuid4().hex
src_path = f"/tmp/source_{uid}.png"
tgt_path = f"/tmp/target_{uid}.mp4"
out_path = f"{OUTPUT_DIR}/result_{uid}.mp4"
# Save inputs
source_image.save(src_path)
target_video.save(tgt_path)
# Run facefusion
try:
subprocess.run([
"python", "run.py",
"--source", src_path,
"--target", tgt_path,
"--output", out_path,
"--execution-provider", "cuda", # or "cpu"
"--face-analyser-model", "buffalo_l"
], check=True)
return out_path
except subprocess.CalledProcessError as e:
return f"❌ Error: {str(e)}"
# Gradio UI
with gr.Blocks() as demo:
gr.Markdown("## 🎭 Basic FaceFusion Web UI")
with gr.Row():
src = gr.Image(label="Source Face", type="pil")
tgt = gr.Video(label="Target Video")
run_btn = gr.Button("Run FaceFusion")
result = gr.Video(label="Output Video")
run_btn.click(fn=swap_faces, inputs=[src, tgt], outputs=result)
demo.launch(server_name="0.0.0.0", server_port=7860)
|