diff --git a/roop/uis/__components__/output.py b/roop/uis/__components__/output.py index 14d728683..15e8541f0 100644 --- a/roop/uis/__components__/output.py +++ b/roop/uis/__components__/output.py @@ -1,8 +1,9 @@ -from typing import Any, Dict, Tuple, Optional +from typing import Tuple, Optional import gradio import roop.globals from roop.core import start +from roop.uis.typing import Update from roop.utilities import has_image_extension, has_video_extension, normalize_output_path @@ -31,7 +32,7 @@ def listen() -> None: CLEAR_BUTTON.click(clear, outputs=[OUTPUT_IMAGE, OUTPUT_VIDEO]) -def update() -> Tuple[Dict[str, Any], Dict[str, Any]]: +def update() -> Tuple[Update, Update]: roop.globals.output_path = normalize_output_path(roop.globals.source_path, roop.globals.target_path, '..') if roop.globals.output_path: start() @@ -42,5 +43,5 @@ def update() -> Tuple[Dict[str, Any], Dict[str, Any]]: return gradio.update(value=None, visible=False), gradio.update(value=None, visible=False) -def clear() -> Tuple[Dict[str, Any], Dict[str, Any]]: +def clear() -> Tuple[Update, Update]: return gradio.update(value=None, visible=False), gradio.update(value=None, visible=False) diff --git a/roop/uis/__components__/preview.py b/roop/uis/__components__/preview.py index 1baf52b91..8de0ccebe 100644 --- a/roop/uis/__components__/preview.py +++ b/roop/uis/__components__/preview.py @@ -12,7 +12,7 @@ from roop.processors.frame.core import load_frame_processor_module from roop.typing import Frame from roop.uis import core as ui -from roop.uis.typing import ComponentName +from roop.uis.typing import ComponentName, Update from roop.utilities import is_video, is_image PREVIEW_IMAGE: Optional[gradio.Image] = None @@ -67,7 +67,7 @@ def listen() -> None: component.change(update, inputs=PREVIEW_SLIDER, outputs=[PREVIEW_IMAGE, PREVIEW_SLIDER]) -def update(frame_number: int = 0) -> Tuple[Dict[Any, Any], Dict[Any, Any]]: +def update(frame_number: int = 0) -> Tuple[Update, Update]: sleep(0.5) if is_image(roop.globals.target_path): temp_frame = cv2.imread(roop.globals.target_path) diff --git a/roop/uis/__components__/reference.py b/roop/uis/__components__/reference.py index d880d8ced..2cf4b0421 100644 --- a/roop/uis/__components__/reference.py +++ b/roop/uis/__components__/reference.py @@ -1,4 +1,4 @@ -from typing import Dict, Any, List, Optional +from typing import List, Optional from time import sleep import cv2 @@ -9,7 +9,7 @@ from roop.face_analyser import get_faces_total from roop.face_reference import clear_face_reference from roop.uis import core as ui -from roop.uis.typing import ComponentName +from roop.uis.typing import ComponentName, Update from roop.utilities import is_image, is_video REFERENCE_FACE_POSITION_SLIDER: Optional[gradio.Slider] = None @@ -57,12 +57,12 @@ def listen() -> None: REFERENCE_FACE_POSITION_SLIDER.change(clear_and_update_face_reference_position, inputs=REFERENCE_FACE_POSITION_SLIDER) -def clear_and_update_face_reference_position(reference_face_position: int) -> Dict[Any, Any]: +def clear_and_update_face_reference_position(reference_face_position: int) -> Update: clear_face_reference() return update_face_reference_position(reference_face_position) -def update_face_reference_position(reference_face_position: int) -> Dict[Any, Any]: +def update_face_reference_position(reference_face_position: int) -> Update: sleep(0.5) maximum = 0 roop.globals.reference_face_position = reference_face_position @@ -75,6 +75,6 @@ def update_face_reference_position(reference_face_position: int) -> Dict[Any, An return gradio.update(value=reference_face_position, maximum=maximum) -def update_similar_face_distance(similar_face_distance: float) -> Dict[Any, Any]: +def update_similar_face_distance(similar_face_distance: float) -> Update: roop.globals.similar_face_distance = similar_face_distance return gradio.update(value=similar_face_distance) diff --git a/roop/uis/__components__/settings.py b/roop/uis/__components__/settings.py index b824e3225..747a8023e 100644 --- a/roop/uis/__components__/settings.py +++ b/roop/uis/__components__/settings.py @@ -5,6 +5,7 @@ import roop.globals from roop.processors.frame.core import list_frame_processors_names, load_frame_processor_module, clear_frame_processors_modules from roop.uis import core as ui +from roop.uis.typing import Update FRAME_PROCESSORS_CHECKBOX_GROUP: Optional[gradio.CheckboxGroup] = None EXECUTION_PROVIDERS_CHECKBOX_GROUP: Optional[gradio.CheckboxGroup] = None @@ -99,21 +100,21 @@ def sort_frame_processors(frame_processors: List[str]) -> list[str]: return sorted(list_frame_processors_names(), key=frame_processor_key) -def update_execution_providers(execution_providers: List[str]) -> Dict[Any, Any]: +def update_execution_providers(execution_providers: List[str]) -> Update: roop.globals.execution_providers = execution_providers return gradio.update(value=execution_providers) -def update_execution_thread_count(execution_thread_count: int = 1) -> Dict[Any, Any]: +def update_execution_thread_count(execution_thread_count: int = 1) -> Update: roop.globals.execution_thread_count = execution_thread_count return gradio.update(value=execution_thread_count) -def update_execution_queue_count(execution_queue_count: int = 1) -> Dict[Any, Any]: +def update_execution_queue_count(execution_queue_count: int = 1) -> Update: roop.globals.execution_queue_count = execution_queue_count return gradio.update(value=execution_queue_count) -def update_checkbox(name: str, value: bool) -> Dict[Any, Any]: +def update_checkbox(name: str, value: bool) -> Update: setattr(roop.globals, name, value) return gradio.update(value=value) diff --git a/roop/uis/__components__/source.py b/roop/uis/__components__/source.py index ba6a7680b..a7a2ab518 100644 --- a/roop/uis/__components__/source.py +++ b/roop/uis/__components__/source.py @@ -1,8 +1,9 @@ -from typing import Any, Dict, IO, Optional +from typing import Any, IO, Optional import gradio import roop.globals from roop.uis import core as ui +from roop.uis.typing import Update from roop.utilities import is_image SOURCE_FILE: Optional[gradio.File] = None @@ -33,7 +34,7 @@ def listen() -> None: SOURCE_FILE.change(update, inputs=SOURCE_FILE, outputs=SOURCE_IMAGE) -def update(file: IO[Any]) -> Dict[str, Any]: +def update(file: IO[Any]) -> Update: if file and is_image(file.name): roop.globals.source_path = file.name return gradio.update(value=file.name, visible=True) diff --git a/roop/uis/__components__/target.py b/roop/uis/__components__/target.py index 72d8ed683..97440d9a8 100644 --- a/roop/uis/__components__/target.py +++ b/roop/uis/__components__/target.py @@ -1,9 +1,10 @@ -from typing import Any, Dict, IO, Tuple, Optional +from typing import Any, IO, Tuple, Optional import gradio import roop.globals from roop.face_reference import clear_face_reference from roop.uis import core as ui +from roop.uis.typing import Update from roop.utilities import is_image, is_video TARGET_FILE: Optional[gradio.File] = None @@ -42,7 +43,7 @@ def listen() -> None: TARGET_FILE.change(update, inputs=TARGET_FILE, outputs=[TARGET_IMAGE, TARGET_VIDEO]) -def update(file: IO[Any]) -> Tuple[Dict[str, Any], Dict[str, Any]]: +def update(file: IO[Any]) -> Tuple[Update, Update]: clear_face_reference() if file and is_image(file.name): roop.globals.target_path = file.name diff --git a/roop/uis/core.py b/roop/uis/core.py index 4c6bf7ccc..872314686 100644 --- a/roop/uis/core.py +++ b/roop/uis/core.py @@ -6,6 +6,7 @@ import gradio import roop.globals +import roop.metadata from roop.typing import Frame from roop.uis.typing import Component, ComponentName from roop.utilities import list_module_names @@ -18,7 +19,7 @@ def init() -> None: - with gradio.Blocks(theme=get_theme()) as ui: + with gradio.Blocks(theme=get_theme(), title=roop.metadata.name) as ui: for ui_layout in roop.globals.ui_layouts: ui_layout_module = load_ui_layout_module(ui_layout) ui_layout_module.render() diff --git a/roop/uis/typing.py b/roop/uis/typing.py index eb4215497..bc8f5e66c 100644 --- a/roop/uis/typing.py +++ b/roop/uis/typing.py @@ -1,4 +1,4 @@ -from typing import Literal +from typing import Literal, Dict, Any import gradio Component = gradio.File or gradio.Image or gradio.Video or gradio.Slider @@ -11,3 +11,4 @@ 'frame_processors_checkbox_group', 'many_faces_checkbox' ] +Update = Dict[Any, Any]