Spaces:
Running
Running
prithivMLmods
commited on
Commit
•
181c919
1
Parent(s):
7f47aaa
Update app.py
Browse files
app.py
CHANGED
@@ -1,71 +1,71 @@
|
|
1 |
-
# -* coding:UTF-8 -*
|
2 |
-
# !/usr/bin/env python
|
3 |
-
import numpy as np
|
4 |
-
import gradio as gr
|
5 |
-
import roop.globals
|
6 |
-
from roop.core import (
|
7 |
-
start,
|
8 |
-
decode_execution_providers,
|
9 |
-
suggest_max_memory,
|
10 |
-
suggest_execution_threads,
|
11 |
-
)
|
12 |
-
from roop.processors.frame.core import get_frame_processors_modules
|
13 |
-
from roop.utilities import normalize_output_path
|
14 |
-
import os
|
15 |
-
from PIL import Image
|
16 |
-
|
17 |
-
def swap_face(source_file, target_file,doFaceEnhancer):
|
18 |
-
|
19 |
-
source_path = "input.jpg"
|
20 |
-
target_path = "target.jpg"
|
21 |
-
|
22 |
-
source_image = Image.fromarray(source_file)
|
23 |
-
source_image.save(source_path)
|
24 |
-
target_image = Image.fromarray(target_file)
|
25 |
-
target_image.save(target_path)
|
26 |
-
|
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 |
-
roop.globals.output_path = normalize_output_path(
|
34 |
-
roop.globals.source_path, roop.globals.target_path, output_path
|
35 |
-
)
|
36 |
-
if doFaceEnhancer == True:
|
37 |
-
roop.globals.frame_processors = ["face_swapper","face_enhancer"]
|
38 |
-
else:
|
39 |
-
roop.globals.frame_processors = ["face_swapper"]
|
40 |
-
roop.globals.headless = True
|
41 |
-
roop.globals.keep_fps = True
|
42 |
-
roop.globals.keep_audio = True
|
43 |
-
roop.globals.keep_frames = False
|
44 |
-
roop.globals.many_faces = False
|
45 |
-
roop.globals.video_encoder = "libx264"
|
46 |
-
roop.globals.video_quality = 18
|
47 |
-
roop.globals.max_memory = suggest_max_memory()
|
48 |
-
roop.globals.execution_providers = decode_execution_providers(["cuda"])
|
49 |
-
roop.globals.execution_threads = suggest_execution_threads()
|
50 |
-
|
51 |
-
print(
|
52 |
-
"start process",
|
53 |
-
roop.globals.source_path,
|
54 |
-
roop.globals.target_path,
|
55 |
-
roop.globals.output_path,
|
56 |
-
)
|
57 |
-
|
58 |
-
for frame_processor in get_frame_processors_modules(
|
59 |
-
roop.globals.frame_processors
|
60 |
-
):
|
61 |
-
if not frame_processor.pre_check():
|
62 |
-
return
|
63 |
-
|
64 |
-
start()
|
65 |
-
return output_path
|
66 |
-
|
67 |
-
|
68 |
-
app = gr.Interface(
|
69 |
-
fn=swap_face, inputs=[gr.Image(), gr.Image(),gr.Checkbox(label="face_enhancer?", info="do face enhancer?")], outputs="image", theme="
|
70 |
-
)
|
71 |
-
app.launch()
|
|
|
1 |
+
# -* coding:UTF-8 -*
|
2 |
+
# !/usr/bin/env python
|
3 |
+
import numpy as np
|
4 |
+
import gradio as gr
|
5 |
+
import roop.globals
|
6 |
+
from roop.core import (
|
7 |
+
start,
|
8 |
+
decode_execution_providers,
|
9 |
+
suggest_max_memory,
|
10 |
+
suggest_execution_threads,
|
11 |
+
)
|
12 |
+
from roop.processors.frame.core import get_frame_processors_modules
|
13 |
+
from roop.utilities import normalize_output_path
|
14 |
+
import os
|
15 |
+
from PIL import Image
|
16 |
+
|
17 |
+
def swap_face(source_file, target_file,doFaceEnhancer):
|
18 |
+
|
19 |
+
source_path = "input.jpg"
|
20 |
+
target_path = "target.jpg"
|
21 |
+
|
22 |
+
source_image = Image.fromarray(source_file)
|
23 |
+
source_image.save(source_path)
|
24 |
+
target_image = Image.fromarray(target_file)
|
25 |
+
target_image.save(target_path)
|
26 |
+
|
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 |
+
roop.globals.output_path = normalize_output_path(
|
34 |
+
roop.globals.source_path, roop.globals.target_path, output_path
|
35 |
+
)
|
36 |
+
if doFaceEnhancer == True:
|
37 |
+
roop.globals.frame_processors = ["face_swapper","face_enhancer"]
|
38 |
+
else:
|
39 |
+
roop.globals.frame_processors = ["face_swapper"]
|
40 |
+
roop.globals.headless = True
|
41 |
+
roop.globals.keep_fps = True
|
42 |
+
roop.globals.keep_audio = True
|
43 |
+
roop.globals.keep_frames = False
|
44 |
+
roop.globals.many_faces = False
|
45 |
+
roop.globals.video_encoder = "libx264"
|
46 |
+
roop.globals.video_quality = 18
|
47 |
+
roop.globals.max_memory = suggest_max_memory()
|
48 |
+
roop.globals.execution_providers = decode_execution_providers(["cuda"])
|
49 |
+
roop.globals.execution_threads = suggest_execution_threads()
|
50 |
+
|
51 |
+
print(
|
52 |
+
"start process",
|
53 |
+
roop.globals.source_path,
|
54 |
+
roop.globals.target_path,
|
55 |
+
roop.globals.output_path,
|
56 |
+
)
|
57 |
+
|
58 |
+
for frame_processor in get_frame_processors_modules(
|
59 |
+
roop.globals.frame_processors
|
60 |
+
):
|
61 |
+
if not frame_processor.pre_check():
|
62 |
+
return
|
63 |
+
|
64 |
+
start()
|
65 |
+
return output_path
|
66 |
+
|
67 |
+
|
68 |
+
app = gr.Interface(
|
69 |
+
fn=swap_face, inputs=[gr.Image(), gr.Image(),gr.Checkbox(label="face_enhancer?", info="do face enhancer?")], outputs="image", theme="prithivMLmods/Minecraft-Theme"
|
70 |
+
)
|
71 |
+
app.launch()
|