MagicFaceLab commited on
Commit
cc9114e
·
verified ·
1 Parent(s): 71f0b39

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -39
app.py CHANGED
@@ -1,40 +1,22 @@
1
  import gradio as gr
2
- import os
3
- import torch
4
- import cv2
5
- import numpy as np
6
- from roop.utilities.device import get_device
7
- from roop.processors.frame_processor import process_frame
8
-
9
- # 选择 CPU 或 GPU 设备
10
- device = get_device()
11
- print(f"Using device: {device}")
12
-
13
- def swap_face(source_img, target_img):
14
- try:
15
- # 读取输入图像
16
- source = cv2.imread(source_img)
17
- target = cv2.imread(target_img)
18
-
19
- # 进行人脸替换
20
- result = process_frame(source, target, device=device)
21
-
22
- # 保存结果
23
- output_path = "output.jpg"
24
- cv2.imwrite(output_path, result)
25
-
26
- return output_path
27
- except Exception as e:
28
- return str(e)
29
-
30
- with gr.Blocks() as demo:
31
- gr.Markdown("# Roop Face Swap (Hugging Face)")
32
- with gr.Row():
33
- source_img = gr.Image(type="filepath", label="Source Face")
34
- target_img = gr.Image(type="filepath", label="Target Image")
35
- btn = gr.Button("Swap Face")
36
- output_img = gr.Image(label="Output Image")
37
-
38
- btn.click(swap_face, inputs=[source_img, target_img], outputs=output_img)
39
-
40
- demo.launch()
 
1
  import gradio as gr
2
+ import subprocess
3
+
4
+ def swap_faces(source_image, target_image):
5
+ command = [
6
+ "python", "infer.py",
7
+ "--source", source_image,
8
+ "--target", target_image,
9
+ "--output", "output.jpg"
10
+ ]
11
+ subprocess.run(command)
12
+ return "output.jpg"
13
+
14
+ iface = gr.Interface(
15
+ fn=swap_faces,
16
+ inputs=["image", "image"],
17
+ outputs="image",
18
+ title="FaceFusion",
19
+ description="Upload two images and swap faces using FaceFusion."
20
+ )
21
+
22
+ iface.launch(server_name="0.0.0.0", server_port=7860)