Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -32,8 +32,8 @@ def swap_face(source_file, target_file, doFaceEnhancer):
|
|
| 32 |
target_image = Image.fromarray(target_file)
|
| 33 |
target_image.save(target_path)
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
|
| 38 |
# Check if a face is detected in the source image
|
| 39 |
source_face = get_one_face(cv2.imread(source_path))
|
|
@@ -49,20 +49,7 @@ def swap_face(source_file, target_file, doFaceEnhancer):
|
|
| 49 |
normalized_output_path = normalize_output_path(source_path, target_path, output_path)
|
| 50 |
|
| 51 |
frame_processors = ["face_swapper", "face_enhancer"] if doFaceEnhancer else ["face_swapper"]
|
| 52 |
-
headless = True
|
| 53 |
-
keep_fps = True
|
| 54 |
-
keep_audio = True
|
| 55 |
-
keep_frames = False
|
| 56 |
-
many_faces = False
|
| 57 |
-
video_encoder = "libx264"
|
| 58 |
-
video_quality = 18
|
| 59 |
-
max_memory = "12G"
|
| 60 |
-
execution_providers = ["CUDAExecutionProvider", "CPUExecutionProvider"] # 漂u ti锚n GPU, sau 膽贸 l脿 CPU
|
| 61 |
-
reference_face_position = 0
|
| 62 |
-
similar_face_distance = 0.6
|
| 63 |
|
| 64 |
-
# print("Available providers:", ort.get_available_providers()) # Ki峄僲 tra c谩c provider hi峄噉 c贸
|
| 65 |
-
# print("Configured execution providers:", execution_providers)
|
| 66 |
|
| 67 |
for frame_processor in get_frame_processors_modules(frame_processors):
|
| 68 |
if not frame_processor.pre_check():
|
|
@@ -73,17 +60,19 @@ def swap_face(source_file, target_file, doFaceEnhancer):
|
|
| 73 |
roop.globals.target_path = target_path
|
| 74 |
roop.globals.output_path = normalized_output_path
|
| 75 |
roop.globals.frame_processors = frame_processors
|
| 76 |
-
roop.globals.headless =
|
| 77 |
-
roop.globals.keep_fps =
|
| 78 |
-
roop.globals.keep_audio =
|
| 79 |
-
roop.globals.keep_frames =
|
| 80 |
-
roop.globals.many_faces =
|
| 81 |
-
roop.globals.video_encoder =
|
| 82 |
-
roop.globals.video_quality =
|
| 83 |
-
roop.globals.execution_providers =
|
| 84 |
-
roop.globals.reference_face_position =
|
| 85 |
-
roop.globals.similar_face_distance =
|
| 86 |
-
|
|
|
|
|
|
|
| 87 |
start()
|
| 88 |
return normalized_output_path
|
| 89 |
|
|
@@ -96,4 +85,4 @@ app = gr.Interface(
|
|
| 96 |
],
|
| 97 |
outputs="image"
|
| 98 |
)
|
| 99 |
-
app.launch()
|
|
|
|
| 32 |
target_image = Image.fromarray(target_file)
|
| 33 |
target_image.save(target_path)
|
| 34 |
|
| 35 |
+
print("source_path: ", source_path)
|
| 36 |
+
print("target_path: ", target_path)
|
| 37 |
|
| 38 |
# Check if a face is detected in the source image
|
| 39 |
source_face = get_one_face(cv2.imread(source_path))
|
|
|
|
| 49 |
normalized_output_path = normalize_output_path(source_path, target_path, output_path)
|
| 50 |
|
| 51 |
frame_processors = ["face_swapper", "face_enhancer"] if doFaceEnhancer else ["face_swapper"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
|
|
|
|
|
|
| 53 |
|
| 54 |
for frame_processor in get_frame_processors_modules(frame_processors):
|
| 55 |
if not frame_processor.pre_check():
|
|
|
|
| 60 |
roop.globals.target_path = target_path
|
| 61 |
roop.globals.output_path = normalized_output_path
|
| 62 |
roop.globals.frame_processors = frame_processors
|
| 63 |
+
roop.globals.headless = True
|
| 64 |
+
roop.globals.keep_fps = True
|
| 65 |
+
roop.globals.keep_audio = True
|
| 66 |
+
roop.globals.keep_frames = False
|
| 67 |
+
roop.globals.many_faces = False
|
| 68 |
+
roop.globals.video_encoder = "libx264"
|
| 69 |
+
roop.globals.video_quality = 18
|
| 70 |
+
roop.globals.execution_providers = ["CUDAExecutionProvider"]
|
| 71 |
+
roop.globals.reference_face_position = 0
|
| 72 |
+
roop.globals.similar_face_distance = 0.6
|
| 73 |
+
roop.globals.max_memory = 60
|
| 74 |
+
roop.globals.execution_threads = 50
|
| 75 |
+
|
| 76 |
start()
|
| 77 |
return normalized_output_path
|
| 78 |
|
|
|
|
| 85 |
],
|
| 86 |
outputs="image"
|
| 87 |
)
|
| 88 |
+
app.launch()
|