Skip to content

Commit

Permalink
Improve ui labels
Browse files Browse the repository at this point in the history
  • Loading branch information
henryruhs committed Aug 9, 2023
1 parent 622513a commit 114be9a
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 40 deletions.
10 changes: 8 additions & 2 deletions roop/uis/__components__/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ def render() -> None:
with gradio.Row():
START_BUTTON = gradio.Button('Start')
CLEAR_BUTTON = gradio.Button('Clear')
OUTPUT_IMAGE = gradio.Image(label='output_image', visible=False)
OUTPUT_VIDEO = gradio.Video(label='output_video', visible=False)
OUTPUT_IMAGE = gradio.Image(
label='OUTPUT',
visible=False
)
OUTPUT_VIDEO = gradio.Video(
label='OUTPUT',
visible=False
)


def listen() -> None:
Expand Down
32 changes: 15 additions & 17 deletions roop/uis/__components__/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,41 @@
from roop.utilities import is_video, is_image

PREVIEW_IMAGE: Optional[gradio.Image] = None
PREVIEW_SLIDER: Optional[gradio.Slider] = None
PREVIEW_FRAME_SLIDER: Optional[gradio.Slider] = None


def render() -> None:
global PREVIEW_IMAGE
global PREVIEW_SLIDER
global PREVIEW_FRAME_SLIDER

with gradio.Box():
preview_image_args: Dict[str, Any] = {
'label': 'preview_image',
'visible': False
'label': 'PREVIEW'
}
preview_slider_args: Dict[str, Any] = {
'label': 'preview_slider',
preview_frame_slider_args: Dict[str, Any] = {
'label': 'PREVIEW FRAME',
'step': 1,
'visible': False
}
if is_image(roop.globals.target_path):
target_frame = cv2.imread(roop.globals.target_path)
preview_frame = get_preview_frame(target_frame)
preview_image_args['value'] = ui.normalize_frame(preview_frame)
preview_image_args['visible'] = True
if is_video(roop.globals.target_path):
temp_frame = get_video_frame(roop.globals.target_path, roop.globals.reference_frame_number)
preview_frame = get_preview_frame(temp_frame)
preview_image_args['value'] = ui.normalize_frame(preview_frame)
preview_image_args['visible'] = True
preview_slider_args['value'] = roop.globals.reference_frame_number
preview_slider_args['maximum'] = get_video_frame_total(roop.globals.target_path)
preview_slider_args['visible'] = True
preview_frame_slider_args['value'] = roop.globals.reference_frame_number
preview_frame_slider_args['maximum'] = get_video_frame_total(roop.globals.target_path)
preview_frame_slider_args['visible'] = True
PREVIEW_IMAGE = gradio.Image(**preview_image_args)
PREVIEW_SLIDER = gradio.Slider(**preview_slider_args)
ui.register_component('preview_slider', PREVIEW_SLIDER)
PREVIEW_FRAME_SLIDER = gradio.Slider(**preview_frame_slider_args)
ui.register_component('preview_frame_slider', PREVIEW_FRAME_SLIDER)


def listen() -> None:
PREVIEW_SLIDER.change(update, inputs=PREVIEW_SLIDER, outputs=[PREVIEW_IMAGE, PREVIEW_SLIDER], show_progress=False)
PREVIEW_FRAME_SLIDER.change(update, inputs=PREVIEW_FRAME_SLIDER, outputs=[PREVIEW_IMAGE, PREVIEW_FRAME_SLIDER])
component_names: List[ComponentName] = [
'source_file',
'target_file',
Expand All @@ -64,22 +62,22 @@ def listen() -> None:
for component_name in component_names:
component = ui.get_component(component_name)
if component:
component.change(update, inputs=PREVIEW_SLIDER, outputs=[PREVIEW_IMAGE, PREVIEW_SLIDER])
component.change(update, inputs=PREVIEW_FRAME_SLIDER, outputs=[PREVIEW_IMAGE, PREVIEW_FRAME_SLIDER])


def update(frame_number: int = 0) -> Tuple[Update, Update]:
sleep(0.5)
if is_image(roop.globals.target_path):
target_frame = cv2.imread(roop.globals.target_path)
preview_frame = get_preview_frame(target_frame)
return gradio.update(value=ui.normalize_frame(preview_frame), visible=True), gradio.update(value=0, maximum=1, visible=False)
return gradio.update(value=ui.normalize_frame(preview_frame)), gradio.update(value=0, maximum=1, visible=False)
if is_video(roop.globals.target_path):
roop.globals.reference_frame_number = frame_number
video_frame_total = get_video_frame_total(roop.globals.target_path)
temp_frame = get_video_frame(roop.globals.target_path, roop.globals.reference_frame_number)
preview_frame = get_preview_frame(temp_frame)
return gradio.update(value=ui.normalize_frame(preview_frame), visible=True), gradio.update(maximum=video_frame_total, visible=True)
return gradio.update(value=None, visible=False), gradio.update(value=0, maximum=1, visible=False)
return gradio.update(value=ui.normalize_frame(preview_frame)), gradio.update(maximum=video_frame_total, visible=True)
return gradio.update(value=None), gradio.update(value=0, maximum=1, visible=False)


def get_preview_frame(temp_frame: Frame) -> Frame:
Expand Down
6 changes: 3 additions & 3 deletions roop/uis/__components__/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def render() -> None:

with gradio.Box():
reference_face_position_slider_args = {
'label': 'reference_face_position',
'label': 'REFERENCE FACE POSITION',
'value': roop.globals.reference_face_position,
'step': 1,
'maximum': 0
Expand All @@ -35,7 +35,7 @@ def render() -> None:
reference_face_position_slider_args['maximum'] = get_faces_total(temp_frame)
REFERENCE_FACE_POSITION_SLIDER = gradio.Slider(**reference_face_position_slider_args)
SIMILAR_FACE_DISTANCE_SLIDER = gradio.Slider(
label='similar_face_distance',
label='SIMILAR FACE DISTANCE',
value=roop.globals.similar_face_distance,
maximum=2,
step=0.05
Expand All @@ -48,7 +48,7 @@ def listen() -> None:
SIMILAR_FACE_DISTANCE_SLIDER.change(update_similar_face_distance, inputs=SIMILAR_FACE_DISTANCE_SLIDER)
component_names: List[ComponentName] = [
'target_file',
'preview_slider'
'preview_frame_slider'
]
for component_name in component_names:
component = ui.get_component(component_name)
Expand Down
16 changes: 8 additions & 8 deletions roop/uis/__components__/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,46 +30,46 @@ def render() -> None:
with gradio.Column():
with gradio.Box():
FRAME_PROCESSORS_CHECKBOX_GROUP = gradio.CheckboxGroup(
label='frame_processors',
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',
label='EXECUTION PROVIDERS',
choices=onnxruntime.get_available_providers(),
value=roop.globals.execution_providers
)
EXECUTION_THREAD_COUNT_SLIDER = gradio.Slider(
label='execution_thread_count',
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',
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',
label='KEEP FPS',
value=roop.globals.keep_fps
)
KEEP_TEMP_CHECKBOX = gradio.Checkbox(
label='keep_temp',
label='KEEP TEMP',
value=roop.globals.keep_fps
)
SKIP_AUDIO_CHECKBOX = gradio.Checkbox(
label='skip_audio',
label='SKIP AUDIO',
value=roop.globals.skip_audio
)
MANY_FACES_CHECKBOX = gradio.Checkbox(
label='many_faces',
label='MANY FACES',
value=roop.globals.many_faces
)
ui.register_component('many_faces_checkbox', MANY_FACES_CHECKBOX)
Expand Down
6 changes: 3 additions & 3 deletions roop/uis/__components__/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ def render() -> None:
SOURCE_FILE = gradio.File(
file_count='single',
file_types=['.png', '.jpg', '.jpeg', '.webp'],
label='source_path',
label='SOURCE',
value=roop.globals.source_path if is_source_image else None
)
ui.register_component('source_file', SOURCE_FILE)
SOURCE_IMAGE = gradio.Image(
label='source_image',
value=SOURCE_FILE.value['name'] if is_source_image else None,
visible=is_source_image
visible=is_source_image,
show_label=False
)


Expand Down
12 changes: 6 additions & 6 deletions roop/uis/__components__/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ def render() -> None:
TARGET_FILE = gradio.File(
file_count='single',
file_types=['.png', '.jpg', '.jpeg', '.webp', '.mp4'],
label='target_path',
label='TARGET',
value=roop.globals.target_path if is_target_image or is_target_video else None
)
ui.register_component('target_file', TARGET_FILE)
TARGET_IMAGE = gradio.Image(
label='target_image',
value=TARGET_FILE.value['name'] if is_target_image else None,
visible=is_target_image
visible=is_target_image,
show_label=False
)
TARGET_VIDEO = gradio.Video(
label='target_video',
value=TARGET_FILE.value['name'] if is_target_video else None,
visible=is_target_video
visible=is_target_video,
show_label=False
)
ui.register_component('target_file', TARGET_FILE)


def listen() -> None:
Expand Down
2 changes: 1 addition & 1 deletion roop/uis/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
ComponentName = Literal[
'source_file',
'target_file',
'preview_slider',
'preview_frame_slider',
'reference_face_position_slider',
'similar_face_distance_slider',
'frame_processors_checkbox_group',
Expand Down

0 comments on commit 114be9a

Please sign in to comment.