Spaces:
Running
Running
mrbeliever
commited on
Commit
•
282890f
1
Parent(s):
a4b6c5e
Update app.py
Browse files
app.py
CHANGED
@@ -1,72 +1,83 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
import
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
from
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
roop.globals.
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
roop.globals.
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
roop.globals.
|
42 |
-
roop.globals.
|
43 |
-
roop.globals.
|
44 |
-
roop.globals.
|
45 |
-
roop.globals.
|
46 |
-
roop.globals.
|
47 |
-
roop.globals.
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
)
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import gradio as gr
|
3 |
+
import roop.globals
|
4 |
+
from roop.core import (
|
5 |
+
start,
|
6 |
+
decode_execution_providers,
|
7 |
+
suggest_max_memory,
|
8 |
+
suggest_execution_threads,
|
9 |
+
)
|
10 |
+
from roop.processors.frame.core import get_frame_processors_modules
|
11 |
+
from roop.utilities import normalize_output_path
|
12 |
+
import os
|
13 |
+
from PIL import Image
|
14 |
+
|
15 |
+
|
16 |
+
def swap_face(source_file, target_file, doFaceEnhancer):
|
17 |
+
source_path = "input.jpg"
|
18 |
+
target_path = "target.jpg"
|
19 |
+
|
20 |
+
source_image = Image.fromarray(source_file)
|
21 |
+
source_image.save(source_path)
|
22 |
+
target_image = Image.fromarray(target_file)
|
23 |
+
target_image.save(target_path)
|
24 |
+
|
25 |
+
print("source_path: ", source_path)
|
26 |
+
print("target_path: ", target_path)
|
27 |
+
|
28 |
+
roop.globals.source_path = source_path
|
29 |
+
roop.globals.target_path = target_path
|
30 |
+
output_path = "output.jpg"
|
31 |
+
roop.globals.output_path = normalize_output_path(
|
32 |
+
roop.globals.source_path, roop.globals.target_path, output_path
|
33 |
+
)
|
34 |
+
if doFaceEnhancer:
|
35 |
+
roop.globals.frame_processors = ["face_swapper", "face_enhancer"]
|
36 |
+
else:
|
37 |
+
roop.globals.frame_processors = ["face_swapper"]
|
38 |
+
roop.globals.headless = True
|
39 |
+
roop.globals.keep_fps = True
|
40 |
+
roop.globals.keep_audio = True
|
41 |
+
roop.globals.keep_frames = False
|
42 |
+
roop.globals.many_faces = False
|
43 |
+
roop.globals.video_encoder = "libx264"
|
44 |
+
roop.globals.video_quality = 18
|
45 |
+
roop.globals.max_memory = suggest_max_memory()
|
46 |
+
roop.globals.execution_providers = decode_execution_providers(["cuda"])
|
47 |
+
roop.globals.execution_threads = suggest_execution_threads()
|
48 |
+
|
49 |
+
print(
|
50 |
+
"start process",
|
51 |
+
roop.globals.source_path,
|
52 |
+
roop.globals.target_path,
|
53 |
+
roop.globals.output_path,
|
54 |
+
)
|
55 |
+
|
56 |
+
for frame_processor in get_frame_processors_modules(
|
57 |
+
roop.globals.frame_processors
|
58 |
+
):
|
59 |
+
if not frame_processor.pre_check():
|
60 |
+
return
|
61 |
+
|
62 |
+
start()
|
63 |
+
return output_path
|
64 |
+
|
65 |
+
|
66 |
+
with gr.Blocks() as app:
|
67 |
+
with gr.Column():
|
68 |
+
with gr.Row():
|
69 |
+
gr.Markdown("")
|
70 |
+
with gr.Row():
|
71 |
+
source_file = gr.Image(label="Source File")
|
72 |
+
target_file = gr.Image(label="Target File")
|
73 |
+
with gr.Row():
|
74 |
+
doFaceEnhancer = gr.Checkbox(label="Face Enhancer", info="Do face enhancer?")
|
75 |
+
with gr.Row():
|
76 |
+
swap_button = gr.Button("Swap Face")
|
77 |
+
with gr.Row():
|
78 |
+
output_image = gr.Image(label="Output")
|
79 |
+
|
80 |
+
swap_button.click(swap_face, inputs=[source_file, target_file, doFaceEnhancer], outputs=output_image)
|
81 |
+
|
82 |
+
app.launch()
|
83 |
+
|