Skip to content

Commit

Permalink
Use slider to trim start and end frame
Browse files Browse the repository at this point in the history
  • Loading branch information
henryruhs committed Aug 10, 2023
1 parent 0bafad1 commit 31a50e1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
32 changes: 19 additions & 13 deletions roop/uis/__components__/trim_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,45 @@
from roop.uis.typing import Update
from roop.utilities import is_video

TRIM_FRAME_START_NUMBER: Optional[gradio.Number] = None
TRIM_FRAME_END_NUMBER: Optional[gradio.Number] = None
TRIM_FRAME_START_SLIDER: Optional[gradio.Slider] = None
TRIM_FRAME_END_SLIDER: Optional[gradio.Slider] = None


def render() -> None:
global TRIM_FRAME_START_NUMBER
global TRIM_FRAME_END_NUMBER
global TRIM_FRAME_START_SLIDER
global TRIM_FRAME_END_SLIDER

with gradio.Box():
trim_frame_start_number_args: Dict[str, Any] = {
trim_frame_start_slider_args: Dict[str, Any] = {
'label': 'TRIM FRAME START',
'value': roop.globals.trim_frame_start,
'step': 1,
'visible': False
}
trim_frame_end_number_args: Dict[str, Any] = {
trim_frame_end_slider_args: Dict[str, Any] = {
'label': 'TRIM FRAME END',
'value': roop.globals.trim_frame_end,
'step': 1,
'visible': False
}
if is_video(roop.globals.target_path):
trim_frame_start_number_args['visible'] = True
trim_frame_end_number_args['visible'] = True
video_frame_total = get_video_frame_total(roop.globals.target_path)
trim_frame_start_slider_args['maximum'] = video_frame_total
trim_frame_start_slider_args['visible'] = True
trim_frame_end_slider_args['value'] = video_frame_total
trim_frame_end_slider_args['maximum'] = video_frame_total
trim_frame_end_slider_args['visible'] = True
with gradio.Row():
TRIM_FRAME_START_NUMBER = gradio.Number(**trim_frame_start_number_args)
TRIM_FRAME_END_NUMBER = gradio.Number(**trim_frame_end_number_args)
TRIM_FRAME_START_SLIDER = gradio.Slider(**trim_frame_start_slider_args)
TRIM_FRAME_END_SLIDER = gradio.Slider(**trim_frame_end_slider_args)


def listen() -> None:
target_file = ui.get_component('target_file')
if target_file:
target_file.change(remote_update, outputs=[TRIM_FRAME_START_NUMBER, TRIM_FRAME_END_NUMBER])
TRIM_FRAME_START_NUMBER.change(lambda value: update_number('trim_frame_start', int(value)), inputs=TRIM_FRAME_START_NUMBER, outputs=TRIM_FRAME_START_NUMBER)
TRIM_FRAME_END_NUMBER.change(lambda value: update_number('trim_frame_end', int(value)), inputs=TRIM_FRAME_END_NUMBER, outputs=TRIM_FRAME_END_NUMBER)
target_file.change(remote_update, outputs=[TRIM_FRAME_START_SLIDER, TRIM_FRAME_END_SLIDER])
TRIM_FRAME_START_SLIDER.change(lambda value: update_number('trim_frame_start', int(value)), inputs=TRIM_FRAME_START_SLIDER, outputs=TRIM_FRAME_START_SLIDER)
TRIM_FRAME_END_SLIDER.change(lambda value: update_number('trim_frame_end', int(value)), inputs=TRIM_FRAME_END_SLIDER, outputs=TRIM_FRAME_END_SLIDER)


def remote_update() -> Tuple[Update, Update]:
Expand Down
4 changes: 4 additions & 0 deletions roop/uis/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def get_theme() -> gradio.Theme:
primary_hue=gradio.themes.colors.red,
secondary_hue=gradio.themes.colors.gray,
font=gradio.themes.GoogleFont('Inter')
).set(
background_fill_primary='*neutral_50',
block_label_text_size='*text_sm',
block_title_text_size='*text_sm'
)


Expand Down

0 comments on commit 31a50e1

Please sign in to comment.