Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
import
|
4 |
import roop.globals
|
5 |
from roop.core import (
|
6 |
start,
|
@@ -10,26 +10,17 @@ from roop.core import (
|
|
10 |
)
|
11 |
from roop.processors.frame.core import get_frame_processors_modules
|
12 |
from roop.utilities import normalize_output_path
|
13 |
-
from
|
14 |
-
import gradio as gr
|
15 |
-
import os
|
16 |
|
17 |
def swap_face(source_file, target_file):
|
18 |
source_image = Image.fromarray(source_file)
|
19 |
source_path = "input.jpg"
|
20 |
source_image.save(source_path, format="JPEG", quality=95)
|
21 |
|
22 |
-
|
23 |
output_path = "output.mp4"
|
24 |
|
25 |
-
roop.globals.source_path
|
26 |
-
roop.globals.target_path = target_file
|
27 |
-
|
28 |
-
|
29 |
|
30 |
-
roop.globals.output_path = normalize_output_path(
|
31 |
-
roop.globals.source_path, roop.globals.target_path, output_path
|
32 |
-
)
|
33 |
roop.globals.frame_processors = ["face_swapper"]
|
34 |
roop.globals.headless = True
|
35 |
roop.globals.keep_fps = True
|
@@ -38,21 +29,26 @@ def swap_face(source_file, target_file):
|
|
38 |
roop.globals.many_faces = False
|
39 |
roop.globals.video_encoder = "libx264"
|
40 |
roop.globals.video_quality = 50
|
41 |
-
roop.globals.max_memory = 14#suggest_max_memory()
|
42 |
roop.globals.execution_providers = decode_execution_providers(["cpu"])
|
43 |
-
roop.globals.execution_threads = 32#suggest_execution_threads()
|
44 |
-
|
45 |
-
|
46 |
-
):
|
47 |
if not frame_processor.pre_check():
|
48 |
return
|
49 |
|
50 |
start()
|
51 |
|
|
|
|
|
52 |
return os.path.join(os.getcwd(), output_path)
|
53 |
|
54 |
app = gr.Interface(
|
55 |
-
fn=swap_face,
|
|
|
|
|
|
|
|
|
56 |
)
|
57 |
|
58 |
-
app.launch()
|
|
|
1 |
+
import os
|
2 |
+
from PIL import Image
|
3 |
+
import gradio as gr
|
4 |
import roop.globals
|
5 |
from roop.core import (
|
6 |
start,
|
|
|
10 |
)
|
11 |
from roop.processors.frame.core import get_frame_processors_modules
|
12 |
from roop.utilities import normalize_output_path
|
13 |
+
from roop.globals import clean_temp
|
|
|
|
|
14 |
|
15 |
def swap_face(source_file, target_file):
|
16 |
source_image = Image.fromarray(source_file)
|
17 |
source_path = "input.jpg"
|
18 |
source_image.save(source_path, format="JPEG", quality=95)
|
19 |
|
|
|
20 |
output_path = "output.mp4"
|
21 |
|
22 |
+
roop.globals.set_global_paths(source_path, target_file, output_path)
|
|
|
|
|
|
|
23 |
|
|
|
|
|
|
|
24 |
roop.globals.frame_processors = ["face_swapper"]
|
25 |
roop.globals.headless = True
|
26 |
roop.globals.keep_fps = True
|
|
|
29 |
roop.globals.many_faces = False
|
30 |
roop.globals.video_encoder = "libx264"
|
31 |
roop.globals.video_quality = 50
|
32 |
+
roop.globals.max_memory = 14 # suggest_max_memory()
|
33 |
roop.globals.execution_providers = decode_execution_providers(["cpu"])
|
34 |
+
roop.globals.execution_threads = 32 # suggest_execution_threads()
|
35 |
+
|
36 |
+
for frame_processor in get_frame_processors_modules(roop.globals.frame_processors):
|
|
|
37 |
if not frame_processor.pre_check():
|
38 |
return
|
39 |
|
40 |
start()
|
41 |
|
42 |
+
clean_temp(roop.globals.target_path)
|
43 |
+
|
44 |
return os.path.join(os.getcwd(), output_path)
|
45 |
|
46 |
app = gr.Interface(
|
47 |
+
fn=swap_face,
|
48 |
+
inputs=[gr.Image(), gr.Video()],
|
49 |
+
outputs=[gr.Video()],
|
50 |
+
description="Sorry for the inconvenience. The model is currently running on the CPU, which might affect performance. We appreciate your understanding.",
|
51 |
+
theme="NoCrypt/miku"
|
52 |
)
|
53 |
|
54 |
+
app.launch()
|