Skip to content

Commit ad0ea84

Browse files
committed
preview tab for copilot
1 parent 0ffb603 commit ad0ea84

File tree

4 files changed

+104
-56
lines changed

4 files changed

+104
-56
lines changed

daras_ai_v2/base.py

Lines changed: 79 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -379,15 +379,55 @@ def render(self):
379379
& button {
380380
padding: 0.4rem !important;
381381
}
382+
383+
& a:has(span.mobile-only-recipe-tab) {
384+
display: block !important;
385+
}
386+
387+
& ul.nav-tabs {
388+
overflow-x: auto;
389+
overflow-y: hidden;
390+
white-space: nowrap;
391+
flex-wrap: nowrap !important;
392+
display: flex;
393+
-webkit-overflow-scrolling: touch;
394+
scrollbar-width: none;
395+
gap: 0.5rem;
396+
}
397+
398+
@media (min-width: 768px) {
399+
& a:has(span.mobile-only-recipe-tab) {
400+
display: none !important;
401+
}
402+
403+
/* RUN as active tab in lg view for preview route */
404+
& span.active-lg button {
405+
color: #000;
406+
border-bottom: 2px solid black;
407+
}
408+
409+
& ul.nav-tabs {
410+
gap: 0;
411+
}
412+
}
382413
"""
383414
),
384415
gui.div(className="position-relative"),
385416
gui.nav_tabs(),
386417
):
387418
for tab in self.get_tabs():
388419
url = self.current_app_url(tab)
389-
with gui.nav_item(url, active=tab == self.tab):
390-
gui.html(tab.title)
420+
with gui.tag(
421+
"span",
422+
className="active-lg"
423+
if (tab == RecipeTabs.run and self.tab == RecipeTabs.preview)
424+
else "",
425+
):
426+
with gui.nav_item(
427+
url,
428+
active=tab == self.tab,
429+
):
430+
gui.html(tab.title)
391431

392432
self._render_saved_generated_timestamp()
393433
with gui.nav_tab_content():
@@ -437,7 +477,7 @@ def _render_header(self):
437477
self.render_social_buttons()
438478

439479
if tbreadcrumbs.has_breadcrumbs():
440-
if self.tab != RecipeTabs.run:
480+
if self.tab != RecipeTabs.run and self.tab != RecipeTabs.preview:
441481
with gui.styled("& h1 { margin-top: 0 }"):
442482
self._render_title(tbreadcrumbs.h1_title)
443483
else:
@@ -1161,15 +1201,13 @@ def get_tabs(self):
11611201

11621202
def render_selected_tab(self):
11631203
match self.tab:
1164-
case RecipeTabs.run:
1204+
case RecipeTabs.run | RecipeTabs.preview:
11651205
if self.current_sr.retention_policy == RetentionPolicy.delete:
11661206
self.render_deleted_output()
11671207
return
11681208

11691209
with gui.styled(OUTPUT_TABS_CSS):
1170-
output_col, input_col = gui.tabs(
1171-
[f"{icons.preview} Preview", f"{icons.edit} Edit"]
1172-
)
1210+
input_col, output_col = gui.columns([3, 2], gap="medium")
11731211
with input_col:
11741212
submitted = self._render_input_col()
11751213
with output_col:
@@ -1725,25 +1763,28 @@ def _render_report_button(self):
17251763
show_settings = True
17261764

17271765
def _render_input_col(self):
1728-
self.render_form_v2()
1729-
placeholder = gui.div()
1766+
with gui.div(
1767+
className="d-none d-lg-block" if self.tab == RecipeTabs.preview else ""
1768+
):
1769+
self.render_form_v2()
1770+
placeholder = gui.div()
17301771

1731-
if self.show_settings:
1732-
with gui.div(className="bg-white"):
1733-
with gui.expander("⚙️ Settings"):
1734-
self.render_settings()
1735-
if self.functions_in_settings:
1736-
functions_input(self.request.user)
1772+
if self.show_settings:
1773+
with gui.div(className="bg-white"):
1774+
with gui.expander("⚙️ Settings"):
1775+
self.render_settings()
1776+
if self.functions_in_settings:
1777+
functions_input(self.request.user)
17371778

1738-
with placeholder:
1739-
self.render_variables()
1779+
with placeholder:
1780+
self.render_variables()
17401781

1741-
submitted = self.render_submit_button()
1742-
with gui.div(style={"textAlign": "right", "fontSize": "smaller"}):
1743-
terms_caption = self.get_terms_caption()
1744-
gui.caption(f"_{terms_caption}_")
1782+
submitted = self.render_submit_button()
1783+
with gui.div(style={"textAlign": "right", "fontSize": "smaller"}):
1784+
terms_caption = self.get_terms_caption()
1785+
gui.caption(f"_{terms_caption}_")
17451786

1746-
return submitted
1787+
return submitted
17471788

17481789
def get_terms_caption(self):
17491790
return "With each run, you agree to Gooey.AI's [terms](https://gooey.ai/terms) & [privacy policy](https://gooey.ai/privacy)."
@@ -1795,7 +1836,12 @@ def _render_output_col(self, *, submitted: bool = False, is_deleted: bool = Fals
17951836
if submitted:
17961837
self.submit_and_redirect()
17971838

1798-
with gui.div(style=dict(position="sticky", top="0.5rem")):
1839+
with gui.div(
1840+
style=dict(position="sticky", top="0.5rem"),
1841+
className="d-none d-lg-block pb-2"
1842+
if self.tab == RecipeTabs.run and self.workflow in PREVIEW_ROUTE_WORKFLOWS
1843+
else "",
1844+
):
17991845
run_state = self.get_run_state(gui.session_state)
18001846
if run_state == RecipeRunState.failed:
18011847
self._render_failed_output()
@@ -2487,36 +2533,16 @@ class TitleValidationError(Exception):
24872533
pass
24882534

24892535

2536+
PREVIEW_ROUTE_WORKFLOWS = [Workflow.VIDEO_BOTS]
24902537
OUTPUT_TABS_CSS = """
2491-
& [data-reach-tab-list] {
2492-
text-align: center; margin-top: 0
2493-
}
2494-
@media (min-width: 768px) {
2495-
& [data-reach-tab-list] {
2496-
display: none;
2538+
& {
2539+
margin: -1rem 0 1rem 0;
2540+
padding-top: 1rem;
24972541
}
2498-
& [data-reach-tab-panels] {
2499-
display: flex;
2500-
flex-direction: row-reverse;
2501-
width: 100%;
2502-
background-color: #f9f9f9;
2503-
padding: 10px;
2504-
margin-top: -1rem;
2505-
}
2506-
& [data-reach-tab-panels] > div:nth-child(2) {
2507-
flex: 0 1 auto;
2508-
width: 60%;
2509-
max-width: 100%;
2510-
padding-right: 0.75rem;
2511-
}
2512-
& [data-reach-tab-panels] > div:nth-child(1) {
2513-
flex: 0 0 auto;
2514-
width: 40%;
2515-
max-width: 100%;
2516-
padding-left: 0.75rem;
2517-
}
2518-
& [data-reach-tab-panel][hidden] {
2519-
display: block !important;
2542+
@media (min-width: 768px) {
2543+
& {
2544+
background-color: #f9f9f9;
2545+
}
25202546
}
2521-
}
2522-
"""
2547+
2548+
"""

daras_ai_v2/meta_content.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,12 @@ def robots_tag_for_page(
220220
match page.tab:
221221
case RecipeTabs.run if is_root or is_example:
222222
no_follow, no_index = False, False
223+
case RecipeTabs.preview if is_root or is_example:
224+
no_follow, no_index = False, False
223225
case RecipeTabs.run: # ordinary run (not example)
224226
no_follow, no_index = False, True
227+
case RecipeTabs.preview:
228+
no_follow, no_index = False, True
225229
case RecipeTabs.examples:
226230
no_follow, no_index = False, False
227231
case RecipeTabs.run_as_api:

recipes/VideoBots.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1479,11 +1479,12 @@ def lipsync_step(self, request, response):
14791479
response.output_video.append(lip_state["output_video"])
14801480

14811481
def render_header_extra(self):
1482-
if self.tab == RecipeTabs.run:
1482+
if self.tab == RecipeTabs.run or self.tab == RecipeTabs.preview:
14831483
render_demo_buttons_header(self.current_pr)
14841484

14851485
def get_tabs(self):
14861486
tabs = super().get_tabs()
1487+
tabs.insert(1, RecipeTabs.preview)
14871488
tabs.extend([RecipeTabs.integrations])
14881489
return tabs
14891490

routers/root.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,18 @@ def chat_lib_route(request: Request, integration_id: str, integration_name: str
592592
)
593593

594594

595+
@gui.route(
596+
app,
597+
"/{page_slug}/preview/",
598+
"/{page_slug}/{run_slug}/preview/",
599+
"/{page_slug}/{run_slug}-{example_id}/preview/",
600+
)
601+
def preview_route(
602+
request: Request, page_slug: str, run_slug: str = None, example_id: str = None
603+
):
604+
return render_recipe_page(request, page_slug, RecipeTabs.preview, example_id)
605+
606+
595607
@gui.route(
596608
app,
597609
"/{path:path}",
@@ -821,8 +833,13 @@ class TabData(typing.NamedTuple):
821833

822834

823835
class RecipeTabs(TabData, Enum):
836+
preview = TabData(
837+
title=f"<span class='mobile-only-recipe-tab'>{icons.preview} Preview</span>",
838+
label="",
839+
route=preview_route,
840+
)
824841
run = TabData(
825-
title=f"{icons.run} <span class='d-none d-lg-inline'>Run</span>",
842+
title=f"{icons.run} Run",
826843
label="",
827844
route=recipe_or_handle_or_static,
828845
)
@@ -842,7 +859,7 @@ class RecipeTabs(TabData, Enum):
842859
route=history_route,
843860
)
844861
integrations = TabData(
845-
title=f'<img width="20" height="20" style="margin-right: 4px;margin-top: -3px" src="{icons.integrations_img}" alt="Facebook, Whatsapp, Slack, Instagram Icons"> <span class="d-none d-lg-inline">Integrations</span>',
862+
title=f'<img width="20" height="20" style="margin-right: 4px;margin-top: -3px" src="{icons.integrations_img}" alt="Facebook, Whatsapp, Slack, Instagram Icons"> Integrations',
846863
label="Integrations",
847864
route=integrations_route,
848865
)

0 commit comments

Comments
 (0)