Spaces:
Running
Running
add face_enhancer switch option
Browse files- app.py +6 -3
- roop/core.py +6 -4
- roop/processors/frame/core.py +9 -2
- roop/processors/frame/face_enhancer.py +1 -0
- roop/processors/frame/face_swapper.py +1 -1
app.py
CHANGED
|
@@ -15,7 +15,7 @@ import os
|
|
| 15 |
from PIL import Image
|
| 16 |
|
| 17 |
|
| 18 |
-
def swap_face(source_file, target_file):
|
| 19 |
|
| 20 |
source_path = "input.jpg"
|
| 21 |
target_path = "target.jpg"
|
|
@@ -34,7 +34,10 @@ def swap_face(source_file, target_file):
|
|
| 34 |
roop.globals.output_path = normalize_output_path(
|
| 35 |
roop.globals.source_path, roop.globals.target_path, output_path
|
| 36 |
)
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
| 38 |
roop.globals.headless = True
|
| 39 |
roop.globals.keep_fps = True
|
| 40 |
roop.globals.keep_audio = True
|
|
@@ -64,6 +67,6 @@ def swap_face(source_file, target_file):
|
|
| 64 |
|
| 65 |
|
| 66 |
app = gr.Interface(
|
| 67 |
-
fn=swap_face, inputs=[gr.Image(), gr.Image()], outputs="image"
|
| 68 |
)
|
| 69 |
app.launch()
|
|
|
|
| 15 |
from PIL import Image
|
| 16 |
|
| 17 |
|
| 18 |
+
def swap_face(source_file, target_file,doFaceEnhancer):
|
| 19 |
|
| 20 |
source_path = "input.jpg"
|
| 21 |
target_path = "target.jpg"
|
|
|
|
| 34 |
roop.globals.output_path = normalize_output_path(
|
| 35 |
roop.globals.source_path, roop.globals.target_path, output_path
|
| 36 |
)
|
| 37 |
+
if doFaceEnhancer == True:
|
| 38 |
+
roop.globals.frame_processors = ["face_swapper","face_enhancer"]
|
| 39 |
+
else:
|
| 40 |
+
roop.globals.frame_processors = ["face_swapper"]
|
| 41 |
roop.globals.headless = True
|
| 42 |
roop.globals.keep_fps = True
|
| 43 |
roop.globals.keep_audio = True
|
|
|
|
| 67 |
|
| 68 |
|
| 69 |
app = gr.Interface(
|
| 70 |
+
fn=swap_face, inputs=[gr.Image(), gr.Image(),gr.Checkbox(label="face_enhancer?", info="do face enhancer?")], outputs="image"
|
| 71 |
)
|
| 72 |
app.launch()
|
roop/core.py
CHANGED
|
@@ -146,10 +146,12 @@ def start() -> None:
|
|
| 146 |
destroy()
|
| 147 |
shutil.copy2(roop.globals.target_path, roop.globals.output_path)
|
| 148 |
for frame_processor in get_frame_processors_modules(roop.globals.frame_processors):
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
|
|
|
|
|
|
| 153 |
if is_image(roop.globals.target_path):
|
| 154 |
update_status('Processing to image succeed!')
|
| 155 |
else:
|
|
|
|
| 146 |
destroy()
|
| 147 |
shutil.copy2(roop.globals.target_path, roop.globals.output_path)
|
| 148 |
for frame_processor in get_frame_processors_modules(roop.globals.frame_processors):
|
| 149 |
+
for frame_processor_name in roop.globals.frame_processors:
|
| 150 |
+
if frame_processor_name == frame_processor.frame_name:
|
| 151 |
+
update_status('Progressing...', frame_processor.NAME)
|
| 152 |
+
frame_processor.process_image(roop.globals.source_path, roop.globals.output_path, roop.globals.output_path)
|
| 153 |
+
frame_processor.post_process()
|
| 154 |
+
release_resources()
|
| 155 |
if is_image(roop.globals.target_path):
|
| 156 |
update_status('Processing to image succeed!')
|
| 157 |
else:
|
roop/processors/frame/core.py
CHANGED
|
@@ -35,10 +35,17 @@ def load_frame_processor_module(frame_processor: str) -> Any:
|
|
| 35 |
def get_frame_processors_modules(frame_processors: List[str]) -> List[ModuleType]:
|
| 36 |
global FRAME_PROCESSORS_MODULES
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
frame_processor_module = load_frame_processor_module(frame_processor)
|
| 41 |
FRAME_PROCESSORS_MODULES.append(frame_processor_module)
|
|
|
|
|
|
|
| 42 |
return FRAME_PROCESSORS_MODULES
|
| 43 |
|
| 44 |
|
|
|
|
| 35 |
def get_frame_processors_modules(frame_processors: List[str]) -> List[ModuleType]:
|
| 36 |
global FRAME_PROCESSORS_MODULES
|
| 37 |
|
| 38 |
+
for frame_processor in frame_processors:
|
| 39 |
+
found = False
|
| 40 |
+
for frame_processor_module in FRAME_PROCESSORS_MODULES:
|
| 41 |
+
if frame_processor_module.frame_name == frame_processor:
|
| 42 |
+
found = True
|
| 43 |
+
break
|
| 44 |
+
if not found:
|
| 45 |
frame_processor_module = load_frame_processor_module(frame_processor)
|
| 46 |
FRAME_PROCESSORS_MODULES.append(frame_processor_module)
|
| 47 |
+
# if not FRAME_PROCESSORS_MODULES:
|
| 48 |
+
|
| 49 |
return FRAME_PROCESSORS_MODULES
|
| 50 |
|
| 51 |
|
roop/processors/frame/face_enhancer.py
CHANGED
|
@@ -14,6 +14,7 @@ FACE_ENHANCER = None
|
|
| 14 |
THREAD_SEMAPHORE = threading.Semaphore()
|
| 15 |
THREAD_LOCK = threading.Lock()
|
| 16 |
NAME = 'ROOP.FACE-ENHANCER'
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
def get_face_enhancer() -> Any:
|
|
|
|
| 14 |
THREAD_SEMAPHORE = threading.Semaphore()
|
| 15 |
THREAD_LOCK = threading.Lock()
|
| 16 |
NAME = 'ROOP.FACE-ENHANCER'
|
| 17 |
+
frame_name = 'face_enhancer'
|
| 18 |
|
| 19 |
|
| 20 |
def get_face_enhancer() -> Any:
|
roop/processors/frame/face_swapper.py
CHANGED
|
@@ -13,7 +13,7 @@ from roop.utilities import conditional_download, resolve_relative_path, is_image
|
|
| 13 |
FACE_SWAPPER = None
|
| 14 |
THREAD_LOCK = threading.Lock()
|
| 15 |
NAME = 'ROOP.FACE-SWAPPER'
|
| 16 |
-
|
| 17 |
|
| 18 |
def get_face_swapper() -> Any:
|
| 19 |
global FACE_SWAPPER
|
|
|
|
| 13 |
FACE_SWAPPER = None
|
| 14 |
THREAD_LOCK = threading.Lock()
|
| 15 |
NAME = 'ROOP.FACE-SWAPPER'
|
| 16 |
+
frame_name = 'face_swapper'
|
| 17 |
|
| 18 |
def get_face_swapper() -> Any:
|
| 19 |
global FACE_SWAPPER
|