Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -15,7 +15,6 @@ import spaces
|
|
15 |
|
16 |
@spaces.GPU
|
17 |
def swap_face(source_file, target_file, doFaceEnhancer):
|
18 |
-
|
19 |
source_path = "input.jpg"
|
20 |
target_path = "target.jpg"
|
21 |
|
@@ -27,50 +26,52 @@ def swap_face(source_file, target_file, doFaceEnhancer):
|
|
27 |
print("source_path: ", source_path)
|
28 |
print("target_path: ", target_path)
|
29 |
|
30 |
-
roop.globals.source_path = source_path
|
31 |
-
roop.globals.target_path = target_path
|
32 |
output_path = "output.jpg"
|
33 |
-
|
34 |
-
roop.globals.source_path, roop.globals.target_path, output_path
|
35 |
-
)
|
36 |
-
if doFaceEnhancer:
|
37 |
-
roop.globals.frame_processors = ["face_swapper", "face_enhancer"]
|
38 |
-
else:
|
39 |
-
roop.globals.frame_processors = ["face_swapper"]
|
40 |
-
|
41 |
-
roop.globals.headless = True
|
42 |
-
roop.globals.keep_fps = True
|
43 |
-
roop.globals.keep_audio = True
|
44 |
-
roop.globals.keep_frames = False
|
45 |
-
roop.globals.many_faces = False
|
46 |
-
roop.globals.video_encoder = "libx264"
|
47 |
-
roop.globals.video_quality = 18
|
48 |
-
roop.globals.max_memory = "4G" # Sử dụng giá trị mặc định
|
49 |
-
roop.globals.execution_providers = decode_execution_providers(["cuda"])
|
50 |
-
roop.globals.execution_threads = 4 # Sử dụng giá trị mặc định
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
print(
|
61 |
"start process",
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
)
|
66 |
|
67 |
-
for frame_processor in get_frame_processors_modules(
|
68 |
-
roop.globals.frame_processors
|
69 |
-
):
|
70 |
if not frame_processor.pre_check():
|
71 |
print(f"Pre-check failed for {frame_processor}")
|
72 |
return
|
73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
start()
|
75 |
return output_path
|
76 |
|
|
|
15 |
|
16 |
@spaces.GPU
|
17 |
def swap_face(source_file, target_file, doFaceEnhancer):
|
|
|
18 |
source_path = "input.jpg"
|
19 |
target_path = "target.jpg"
|
20 |
|
|
|
26 |
print("source_path: ", source_path)
|
27 |
print("target_path: ", target_path)
|
28 |
|
|
|
|
|
29 |
output_path = "output.jpg"
|
30 |
+
normalized_output_path = normalize_output_path(source_path, target_path, output_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
+
frame_processors = ["face_swapper", "face_enhancer"] if doFaceEnhancer else ["face_swapper"]
|
33 |
+
headless = True
|
34 |
+
keep_fps = True
|
35 |
+
keep_audio = True
|
36 |
+
keep_frames = False
|
37 |
+
many_faces = False
|
38 |
+
video_encoder = "libx264"
|
39 |
+
video_quality = 18
|
40 |
+
max_memory = "4G"
|
41 |
+
execution_providers = decode_execution_providers(["cuda"])
|
42 |
+
execution_threads = 4
|
43 |
+
reference_face_position = 0
|
44 |
+
similar_face_distance = 0.6
|
45 |
|
46 |
print(
|
47 |
"start process",
|
48 |
+
source_path,
|
49 |
+
target_path,
|
50 |
+
normalized_output_path,
|
51 |
)
|
52 |
|
53 |
+
for frame_processor in get_frame_processors_modules(frame_processors):
|
|
|
|
|
54 |
if not frame_processor.pre_check():
|
55 |
print(f"Pre-check failed for {frame_processor}")
|
56 |
return
|
57 |
|
58 |
+
roop.globals.source_path = source_path
|
59 |
+
roop.globals.target_path = target_path
|
60 |
+
roop.globals.output_path = normalized_output_path
|
61 |
+
roop.globals.frame_processors = frame_processors
|
62 |
+
roop.globals.headless = headless
|
63 |
+
roop.globals.keep_fps = keep_fps
|
64 |
+
roop.globals.keep_audio = keep_audio
|
65 |
+
roop.globals.keep_frames = keep_frames
|
66 |
+
roop.globals.many_faces = many_faces
|
67 |
+
roop.globals.video_encoder = video_encoder
|
68 |
+
roop.globals.video_quality = video_quality
|
69 |
+
roop.globals.max_memory = max_memory
|
70 |
+
roop.globals.execution_providers = execution_providers
|
71 |
+
roop.globals.execution_threads = execution_threads
|
72 |
+
roop.globals.reference_face_position = reference_face_position
|
73 |
+
roop.globals.similar_face_distance = similar_face_distance
|
74 |
+
|
75 |
start()
|
76 |
return output_path
|
77 |
|