Spaces:
Running
Running
perbaikan error
Browse files
app.py
CHANGED
@@ -1,20 +1,18 @@
|
|
1 |
import numpy as np
|
2 |
import gradio as gr
|
3 |
import models_client.globals
|
4 |
-
from
|
5 |
start,
|
6 |
decode_execution_providers,
|
7 |
suggest_max_memory,
|
8 |
suggest_execution_threads,
|
9 |
)
|
10 |
-
from
|
11 |
-
from
|
12 |
import os
|
13 |
from PIL import Image
|
14 |
|
15 |
-
|
16 |
def swap_face(source_file, target_file, doFaceEnhancer):
|
17 |
-
|
18 |
source_path = "input.jpg"
|
19 |
target_path = "target.jpg"
|
20 |
|
@@ -26,36 +24,36 @@ def swap_face(source_file, target_file, doFaceEnhancer):
|
|
26 |
print("source_path: ", source_path)
|
27 |
print("target_path: ", target_path)
|
28 |
|
29 |
-
|
30 |
-
|
31 |
output_path = "output.jpg"
|
32 |
-
|
33 |
-
|
34 |
)
|
35 |
if doFaceEnhancer:
|
36 |
-
|
37 |
else:
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
|
50 |
print(
|
51 |
"start process",
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
)
|
56 |
|
57 |
for frame_processor in get_frame_processors_modules(
|
58 |
-
|
59 |
):
|
60 |
if not frame_processor.pre_check():
|
61 |
return
|
@@ -63,7 +61,6 @@ def swap_face(source_file, target_file, doFaceEnhancer):
|
|
63 |
start()
|
64 |
return output_path
|
65 |
|
66 |
-
|
67 |
html_section_1 = "<div style='text:align:center'><h1>Ai Penganti Wajah</h1></div>"
|
68 |
html_section_2 = "<div style='text:align:center'><p>Unggah gambar sumber dan target Anda untuk bertukar wajah, Kemudian anda bisa meningkatkan kualitas wajah dengan cara mencentang opsi dibawah</p></div>"
|
69 |
|
|
|
1 |
import numpy as np
|
2 |
import gradio as gr
|
3 |
import models_client.globals
|
4 |
+
from models_client.core import (
|
5 |
start,
|
6 |
decode_execution_providers,
|
7 |
suggest_max_memory,
|
8 |
suggest_execution_threads,
|
9 |
)
|
10 |
+
from models_client.processors.frame.core import get_frame_processors_modules
|
11 |
+
from models_client.utilities import normalize_output_path
|
12 |
import os
|
13 |
from PIL import Image
|
14 |
|
|
|
15 |
def swap_face(source_file, target_file, doFaceEnhancer):
|
|
|
16 |
source_path = "input.jpg"
|
17 |
target_path = "target.jpg"
|
18 |
|
|
|
24 |
print("source_path: ", source_path)
|
25 |
print("target_path: ", target_path)
|
26 |
|
27 |
+
models_client.globals.source_path = source_path
|
28 |
+
models_client.globals.target_path = target_path
|
29 |
output_path = "output.jpg"
|
30 |
+
models_client.globals.output_path = normalize_output_path(
|
31 |
+
models_client.globals.source_path, models_client.globals.target_path, output_path
|
32 |
)
|
33 |
if doFaceEnhancer:
|
34 |
+
models_client.globals.frame_processors = ["face_swapper", "face_enhancer"]
|
35 |
else:
|
36 |
+
models_client.globals.frame_processors = ["face_swapper"]
|
37 |
+
models_client.globals.headless = True
|
38 |
+
models_client.globals.keep_fps = True
|
39 |
+
models_client.globals.keep_audio = True
|
40 |
+
models_client.globals.keep_frames = False
|
41 |
+
models_client.globals.many_faces = False
|
42 |
+
models_client.globals.video_encoder = "libx264"
|
43 |
+
models_client.globals.video_quality = 18
|
44 |
+
models_client.globals.max_memory = suggest_max_memory()
|
45 |
+
models_client.globals.execution_providers = decode_execution_providers(["cuda"])
|
46 |
+
models_client.globals.execution_threads = suggest_execution_threads()
|
47 |
|
48 |
print(
|
49 |
"start process",
|
50 |
+
models_client.globals.source_path,
|
51 |
+
models_client.globals.target_path,
|
52 |
+
models_client.globals.output_path,
|
53 |
)
|
54 |
|
55 |
for frame_processor in get_frame_processors_modules(
|
56 |
+
models_client.globals.frame_processors
|
57 |
):
|
58 |
if not frame_processor.pre_check():
|
59 |
return
|
|
|
61 |
start()
|
62 |
return output_path
|
63 |
|
|
|
64 |
html_section_1 = "<div style='text:align:center'><h1>Ai Penganti Wajah</h1></div>"
|
65 |
html_section_2 = "<div style='text:align:center'><p>Unggah gambar sumber dan target Anda untuk bertukar wajah, Kemudian anda bisa meningkatkan kualitas wajah dengan cara mencentang opsi dibawah</p></div>"
|
66 |
|