Skip to content

Commit bf43305

Browse files
committed
feat: bulk runner UI improvements with responsive workflow selection
1 parent 9b6c847 commit bf43305

File tree

3 files changed

+118
-53
lines changed

3 files changed

+118
-53
lines changed

daras_ai_v2/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,10 @@ def get_run_title(cls, sr: SavedRun, pr: PublishedRun | None) -> str:
11401140
def get_recipe_title(cls) -> str:
11411141
return cls.get_root_pr().title or cls.title or cls.workflow.label
11421142

1143+
@classmethod
1144+
def get_recipe_short_title(cls) -> str:
1145+
return f"{cls.workflow.emoji} {cls.workflow.short_title}"
1146+
11431147
def get_explore_image(self) -> str:
11441148
meta = self.workflow.get_or_create_metadata()
11451149
img = meta.default_image or self.explore_image or ""

daras_ai_v2/workflow_url_input.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ def edit_done_button(key: str):
7777

7878
def edit_button(key: str):
7979
gui.button(
80-
'<i class="fa-regular fa-pencil text-warning"></i>',
80+
'<i class="fa-regular fa-pencil text-muted"></i>',
8181
key=key + ":edit-mode",
8282
type="tertiary",
8383
)
8484

8585

8686
def del_button(key: str):
8787
gui.button(
88-
'<i class="fa-regular fa-trash text-danger"></i>',
88+
'<i class="fa-regular fa-trash text-muted"></i>',
8989
key=key,
9090
type="tertiary",
9191
)

recipes/BulkRunner.py

Lines changed: 112 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -412,65 +412,126 @@ def render_description(self):
412412
"""
413413
)
414414

415-
def render_run_url_inputs(self, key: str, del_key: str, d: dict):
416-
from daras_ai_v2.all_pages import all_home_pages
415+
def _render_url_input_only(self, key: str, del_key: str, d: dict, is_mobile: bool):
416+
columns = [8, 4] if is_mobile else [9, 3]
417+
col1, col2 = gui.columns(
418+
columns, responsive=False, style={"--bs-gutter-x": "0.25rem"}
419+
)
417420

418-
init_workflow_selector(d, key)
421+
with col1:
422+
url = gui.text_input(
423+
"",
424+
key=key,
425+
value=d.get("url"),
426+
placeholder="https://gooey.ai/.../?run_id=...",
427+
)
419428

420-
col1, col2, col3, col4 = gui.columns([9, 1, 1, 1], responsive=False)
421-
if not d.get("workflow") and d.get("url"):
422-
with col1:
423-
url = gui.text_input(
424-
"",
425-
key=key,
426-
value=d.get("url"),
427-
placeholder="https://gooey.ai/.../?run_id=...",
428-
)
429-
with col2:
429+
with col2:
430+
with gui.div(className="d-flex justify-content-between"):
430431
edit_done_button(key)
431-
else:
432-
with col1:
433-
scol1, scol2 = gui.columns([1, 1], responsive=False)
432+
gui.url_button(url)
433+
del_button(del_key)
434+
435+
return url
436+
437+
def _render_workflow_selector(self, key: str, d: dict):
438+
from daras_ai_v2.all_pages import all_home_pages
439+
440+
options = {
441+
page_cls.workflow: page_cls.get_recipe_short_title()
442+
for page_cls in all_home_pages
443+
}
444+
last_workflow_key = "__last_run_url_workflow"
445+
workflow = gui.selectbox(
446+
"",
447+
key=key + ":workflow",
448+
value=(d.get("workflow") or gui.session_state.get(last_workflow_key)),
449+
options=options,
450+
format_func=lambda x: options[x],
451+
)
452+
d["workflow"] = workflow
453+
# use this to set default for next time
454+
gui.session_state[last_workflow_key] = workflow
455+
return workflow
456+
457+
def _render_url_selector(self, key: str, d: dict, workflow):
458+
page_cls = Workflow(workflow).page_cls
459+
url_options = get_published_run_options(
460+
page_cls, current_user=self.request.user
461+
)
462+
url_options.update(d.get("--added_workflows", {}))
463+
464+
url = gui.selectbox(
465+
"",
466+
key=key,
467+
options=url_options,
468+
value=d.get("url"),
469+
format_func=lambda x: url_options[x],
470+
)
471+
return url
472+
473+
def _render_workflow_mode_mobile(self, key: str, del_key: str, d: dict):
474+
wcol1, wcol2 = gui.columns(
475+
[8, 4], responsive=False, style={"--bs-gutter-x": "0.25rem"}
476+
)
477+
478+
with wcol1:
479+
with gui.div(className="pt-1"):
480+
workflow = self._render_workflow_selector(key, d)
481+
482+
with wcol2:
483+
with gui.div(className="d-flex justify-content-between"):
484+
edit_button(key)
485+
gui.url_button(d.get("url", ""))
486+
del_button(del_key)
487+
488+
with gui.div(className="pt-2"):
489+
url = self._render_url_selector(key, d, workflow)
490+
491+
return url
492+
493+
def _render_workflow_mode_desktop(self, key: str, del_key: str, d: dict):
494+
col1, col2 = gui.columns(
495+
[9, 3], responsive=False, style={"--bs-gutter-x": "0.25rem"}
496+
)
497+
498+
with col1:
499+
scol1, scol2 = gui.columns(
500+
[3, 9], responsive=False, style={"--bs-gutter-x": "0.5rem"}
501+
)
502+
434503
with scol1:
435504
with gui.div(className="pt-1"):
436-
options = {
437-
page_cls.workflow: page_cls.get_recipe_title()
438-
for page_cls in all_home_pages
439-
}
440-
last_workflow_key = "__last_run_url_workflow"
441-
workflow = gui.selectbox(
442-
"",
443-
key=key + ":workflow",
444-
value=(
445-
d.get("workflow")
446-
or gui.session_state.get(last_workflow_key)
447-
),
448-
options=options,
449-
format_func=lambda x: options[x],
450-
)
451-
d["workflow"] = workflow
452-
# use this to set default for next time
453-
gui.session_state[last_workflow_key] = workflow
505+
workflow = self._render_workflow_selector(key, d)
506+
454507
with scol2:
455-
page_cls = Workflow(workflow).page_cls
456-
options = get_published_run_options(
457-
page_cls, current_user=self.request.user
458-
)
459-
options.update(d.get("--added_workflows", {}))
460508
with gui.div(className="pt-1"):
461-
url = gui.selectbox(
462-
"",
463-
key=key,
464-
options=options,
465-
value=d.get("url"),
466-
format_func=lambda x: options[x],
467-
)
468-
with col2:
509+
url = self._render_url_selector(key, d, workflow)
510+
511+
with col2:
512+
with gui.div(className="d-flex justify-content-between"):
469513
edit_button(key)
470-
with col3:
471-
gui.url_button(url)
472-
with col4:
473-
del_button(del_key)
514+
gui.url_button(url)
515+
del_button(del_key)
516+
517+
return url
518+
519+
def render_run_url_inputs(self, key: str, del_key: str, d: dict):
520+
init_workflow_selector(d, key)
521+
522+
if not d.get("workflow") and d.get("url"):
523+
with gui.div(className="d-block d-lg-none"):
524+
url = self._render_url_input_only(key, del_key, d, is_mobile=True)
525+
526+
with gui.div(className="d-none d-lg-block"):
527+
url = self._render_url_input_only(key, del_key, d, is_mobile=False)
528+
529+
else:
530+
with gui.div(className="d-block d-lg-none"):
531+
url = self._render_workflow_mode_mobile(key, del_key, d)
532+
533+
with gui.div(className="d-none d-lg-block"):
534+
url = self._render_workflow_mode_desktop(key, del_key, d)
474535

475536
try:
476537
url_to_runs(url)

0 commit comments

Comments
 (0)