Skip to content

Commit

Permalink
Break settings into more components
Browse files Browse the repository at this point in the history
  • Loading branch information
henryruhs committed Aug 13, 2023
1 parent 270139b commit 3371710
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 91 deletions.
2 changes: 1 addition & 1 deletion roop/processors/frame/__modules__/face_swapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

FRAME_PROCESSOR = None
THREAD_LOCK = threading.Lock()
NAME = 'ROOP.FRAME_PROCESSOR..FACE_SWAPPER'
NAME = 'ROOP.FRAME_PROCESSOR.FACE_SWAPPER'


def get_frame_processor() -> Any:
Expand Down
62 changes: 62 additions & 0 deletions roop/uis/__components__/execution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from typing import List, Optional
import gradio
import onnxruntime

import roop.globals
from roop.face_analyser import clear_face_analyser
from roop.processors.frame.core import clear_frame_processors_modules
from roop.uis.typing import Update

EXECUTION_PROVIDERS_CHECKBOX_GROUP: Optional[gradio.CheckboxGroup] = None
EXECUTION_THREAD_COUNT_SLIDER: Optional[gradio.Slider] = None
EXECUTION_QUEUE_COUNT_SLIDER: Optional[gradio.Slider] = None


def render() -> None:
global EXECUTION_PROVIDERS_CHECKBOX_GROUP
global EXECUTION_THREAD_COUNT_SLIDER
global EXECUTION_QUEUE_COUNT_SLIDER

with gradio.Box():
EXECUTION_PROVIDERS_CHECKBOX_GROUP = gradio.CheckboxGroup(
label='EXECUTION PROVIDERS',
choices=onnxruntime.get_available_providers(),
value=roop.globals.execution_providers
)
EXECUTION_THREAD_COUNT_SLIDER = gradio.Slider(
label='EXECUTION THREAD COUNT',
value=roop.globals.execution_thread_count,
step=1,
minimum=1,
maximum=128
)
EXECUTION_QUEUE_COUNT_SLIDER = gradio.Slider(
label='EXECUTION QUEUE COUNT',
value=roop.globals.execution_queue_count,
step=1,
minimum=1,
maximum=16
)


def listen() -> None:
EXECUTION_PROVIDERS_CHECKBOX_GROUP.change(update_execution_providers, inputs=EXECUTION_PROVIDERS_CHECKBOX_GROUP, outputs=EXECUTION_PROVIDERS_CHECKBOX_GROUP)
EXECUTION_THREAD_COUNT_SLIDER.change(update_execution_thread_count, inputs=EXECUTION_THREAD_COUNT_SLIDER, outputs=EXECUTION_THREAD_COUNT_SLIDER)
EXECUTION_QUEUE_COUNT_SLIDER.change(update_execution_queue_count, inputs=EXECUTION_QUEUE_COUNT_SLIDER, outputs=EXECUTION_QUEUE_COUNT_SLIDER)


def update_execution_providers(execution_providers: List[str]) -> Update:
clear_face_analyser()
clear_frame_processors_modules()
roop.globals.execution_providers = execution_providers
return gradio.update(value=execution_providers)


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) -> Update:
roop.globals.execution_queue_count = execution_queue_count
return gradio.update(value=execution_queue_count)
38 changes: 38 additions & 0 deletions roop/uis/__components__/processors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from typing import List, Optional
import gradio

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


def render() -> None:
global FRAME_PROCESSORS_CHECKBOX_GROUP

with gradio.Box():
FRAME_PROCESSORS_CHECKBOX_GROUP = gradio.CheckboxGroup(
label='FRAME PROCESSORS',
choices=sort_frame_processors(roop.globals.frame_processors),
value=roop.globals.frame_processors
)
ui.register_component('frame_processors_checkbox_group', FRAME_PROCESSORS_CHECKBOX_GROUP)


def listen() -> None:
FRAME_PROCESSORS_CHECKBOX_GROUP.change(update_frame_processors, inputs=FRAME_PROCESSORS_CHECKBOX_GROUP, outputs=FRAME_PROCESSORS_CHECKBOX_GROUP)


def update_frame_processors(frame_processors: List[str]) -> Update:
clear_frame_processors_modules()
roop.globals.frame_processors = frame_processors
for frame_processor in roop.globals.frame_processors:
frame_processor_module = load_frame_processor_module(frame_processor)
frame_processor_module.pre_check()
return gradio.update(value=frame_processors, choices=sort_frame_processors(frame_processors))


def sort_frame_processors(frame_processors: List[str]) -> list[str]:
return sorted(list_frame_processors_names(), key=lambda frame_processor: frame_processors.index(frame_processor) if frame_processor in frame_processors else len(frame_processors))
103 changes: 14 additions & 89 deletions roop/uis/__components__/settings.py
Original file line number Diff line number Diff line change
@@ -1,115 +1,40 @@
from typing import List, Optional
from typing import Optional
import gradio
import onnxruntime

import roop.globals
from roop.face_analyser import clear_face_analyser
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
EXECUTION_THREAD_COUNT_SLIDER: Optional[gradio.Slider] = None
EXECUTION_QUEUE_COUNT_SLIDER: Optional[gradio.Slider] = None
KEEP_FPS_CHECKBOX: Optional[gradio.Checkbox] = None
KEEP_TEMP_CHECKBOX: Optional[gradio.Checkbox] = None
SKIP_AUDIO_CHECKBOX: Optional[gradio.Checkbox] = None


def render() -> None:
global FRAME_PROCESSORS_CHECKBOX_GROUP
global EXECUTION_PROVIDERS_CHECKBOX_GROUP
global EXECUTION_THREAD_COUNT_SLIDER
global EXECUTION_QUEUE_COUNT_SLIDER
global KEEP_FPS_CHECKBOX
global KEEP_TEMP_CHECKBOX
global SKIP_AUDIO_CHECKBOX

with gradio.Column():
with gradio.Box():
FRAME_PROCESSORS_CHECKBOX_GROUP = gradio.CheckboxGroup(
label='FRAME PROCESSORS',
choices=sort_frame_processors(roop.globals.frame_processors),
value=roop.globals.frame_processors
)
ui.register_component('frame_processors_checkbox_group', FRAME_PROCESSORS_CHECKBOX_GROUP)
with gradio.Box():
EXECUTION_PROVIDERS_CHECKBOX_GROUP = gradio.CheckboxGroup(
label='EXECUTION PROVIDERS',
choices=onnxruntime.get_available_providers(),
value=roop.globals.execution_providers
)
EXECUTION_THREAD_COUNT_SLIDER = gradio.Slider(
label='EXECUTION THREAD COUNT',
value=roop.globals.execution_thread_count,
step=1,
minimum=1,
maximum=128
)
EXECUTION_QUEUE_COUNT_SLIDER = gradio.Slider(
label='EXECUTION QUEUE COUNT',
value=roop.globals.execution_queue_count,
step=1,
minimum=1,
maximum=16
)
with gradio.Box():
KEEP_FPS_CHECKBOX = gradio.Checkbox(
label='KEEP FPS',
value=roop.globals.keep_fps
)
KEEP_TEMP_CHECKBOX = gradio.Checkbox(
label='KEEP TEMP',
value=roop.globals.keep_fps
)
SKIP_AUDIO_CHECKBOX = gradio.Checkbox(
label='SKIP AUDIO',
value=roop.globals.skip_audio
)
with gradio.Box():
KEEP_FPS_CHECKBOX = gradio.Checkbox(
label='KEEP FPS',
value=roop.globals.keep_fps
)
KEEP_TEMP_CHECKBOX = gradio.Checkbox(
label='KEEP TEMP',
value=roop.globals.keep_fps
)
SKIP_AUDIO_CHECKBOX = gradio.Checkbox(
label='SKIP AUDIO',
value=roop.globals.skip_audio
)


def listen() -> None:
FRAME_PROCESSORS_CHECKBOX_GROUP.change(update_frame_processors, inputs=FRAME_PROCESSORS_CHECKBOX_GROUP, outputs=FRAME_PROCESSORS_CHECKBOX_GROUP)
EXECUTION_PROVIDERS_CHECKBOX_GROUP.change(update_execution_providers, inputs=EXECUTION_PROVIDERS_CHECKBOX_GROUP, outputs=EXECUTION_PROVIDERS_CHECKBOX_GROUP)
EXECUTION_THREAD_COUNT_SLIDER.change(update_execution_thread_count, inputs=EXECUTION_THREAD_COUNT_SLIDER, outputs=EXECUTION_THREAD_COUNT_SLIDER)
EXECUTION_QUEUE_COUNT_SLIDER.change(update_execution_queue_count, inputs=EXECUTION_QUEUE_COUNT_SLIDER, outputs=EXECUTION_QUEUE_COUNT_SLIDER)
KEEP_FPS_CHECKBOX.change(lambda value: update_checkbox('keep_fps', value), inputs=KEEP_FPS_CHECKBOX, outputs=KEEP_FPS_CHECKBOX)
KEEP_TEMP_CHECKBOX.change(lambda value: update_checkbox('keep_temp', value), inputs=KEEP_TEMP_CHECKBOX, outputs=KEEP_TEMP_CHECKBOX)
SKIP_AUDIO_CHECKBOX.change(lambda value: update_checkbox('skip_audio', value), inputs=SKIP_AUDIO_CHECKBOX, outputs=SKIP_AUDIO_CHECKBOX)


def update_frame_processors(frame_processors: List[str]) -> Update:
clear_frame_processors_modules()
roop.globals.frame_processors = frame_processors
for frame_processor in roop.globals.frame_processors:
frame_processor_module = load_frame_processor_module(frame_processor)
frame_processor_module.pre_check()
return gradio.update(value=frame_processors, choices=sort_frame_processors(frame_processors))


def sort_frame_processors(frame_processors: List[str]) -> list[str]:
frame_processor_key = lambda frame_processor: frame_processors.index(frame_processor) if frame_processor in frame_processors else len(frame_processors)
return sorted(list_frame_processors_names(), key=frame_processor_key)


def update_execution_providers(execution_providers: List[str]) -> Update:
clear_face_analyser()
clear_frame_processors_modules()
roop.globals.execution_providers = execution_providers
return gradio.update(value=execution_providers)


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) -> Update:
roop.globals.execution_queue_count = execution_queue_count
return gradio.update(value=execution_queue_count)


def update_checkbox(name: str, value: bool) -> Update:
setattr(roop.globals, name, value)
return gradio.update(value=value)
6 changes: 5 additions & 1 deletion roop/uis/__layouts__/default.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import gradio

from roop.uis.__components__ import settings, source, target, preview, trim_frame, face_analyser, face_selector, output
from roop.uis.__components__ import processors, execution, settings, source, target, preview, trim_frame, face_analyser, face_selector, output


def render() -> gradio.Blocks:
with gradio.Blocks() as layout:
with gradio.Row():
with gradio.Column(scale=2):
processors.render()
execution.render()
settings.render()
with gradio.Column(scale=1):
source.render()
Expand All @@ -22,6 +24,8 @@ def render() -> gradio.Blocks:


def listen() -> None:
processors.listen()
execution.listen()
settings.listen()
source.listen()
target.listen()
Expand Down

0 comments on commit 3371710

Please sign in to comment.