MagicFaceLab commited on
Commit
657f39a
·
verified ·
1 Parent(s): 99a1e32

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()