Skip to content

Commit

Permalink
fps radio selection
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderGi committed Dec 16, 2023
1 parent e5ba772 commit 753715e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
25 changes: 24 additions & 1 deletion gooey_ui/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,14 +623,15 @@ def radio(
*,
disabled: bool = False,
label_visibility: LabelVisibility = "visible",
custom: dict | None = None,
) -> T | None:
if not options:
return None
options = list(options)
if not key:
key = md5_values("radio", label, options, help, label_visibility)
value = state.session_state.get(key)
if key not in state.session_state or value not in options:
if key not in state.session_state or (value not in options and not custom):
value = options[0]
state.session_state.setdefault(key, value)
if label_visibility != "visible":
Expand All @@ -649,6 +650,26 @@ def radio(
disabled=disabled,
),
).mount()
if custom:
with div(
className="d-flex", style={"gap": "1ch", "flex-direction": "row-reverse"}
):
with div(className="flex-grow-1"):
state.session_state.setdefault(f"custom-{key}", value)
val = custom["input"](label="", key=f"custom-{key}")
with div():
state.RenderTreeNode(
name="input",
props=dict(
type="radio",
name=key,
label=dedent(str(custom["label"])),
value=val,
defaultChecked=value not in options,
help=help,
disabled=disabled,
),
).mount()
return value


Expand Down Expand Up @@ -741,6 +762,7 @@ def number_input(
help: str = None,
*,
disabled: bool = False,
**props,
) -> float:
value = _input_widget(
input_type="number",
Expand All @@ -753,6 +775,7 @@ def number_input(
min=min_value,
max=max_value,
step=_step_value(min_value, max_value, step),
**props,
)
return value or 0

Expand Down
23 changes: 19 additions & 4 deletions recipes/DeforumSD.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,30 @@ def render_settings(self):
""",
key="rotation_3d_x",
)
st.slider(

st.radio(
"""
###### FPS (Frames per second)
Choose fps for the video.
""",
min_value=10,
max_value=60,
step=1,
options=[2, 10, 24],
format_func=lambda x: {
"2": "Draft: 2 FPS",
"10": "Stop-motion: 10 FPS",
"24": "Film: 24 FPS",
}[str(x)],
key="fps",
custom={
"label": "Custom",
"input": lambda label, key: st.number_input(
label=label,
min_value=1,
max_value=60,
step=1,
key=key,
style={"margin-top": "-28px"},
),
},
)

# st.selectbox(
Expand Down

0 comments on commit 753715e

Please sign in to comment.