Spaces:
Paused
Paused
Download app.py from dartv/facefusion-docker: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/spaces/dartv/facefusion-docker/resolve/main/app.py
- Command line
-
hf download hf://spaces/dartv/facefusion-docker/app.py
-
curl -L -o app.py https://huggingface.co/spaces/dartv/facefusion-docker/resolve/main/app.py
1.26 kB
| 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) | |