From 9a65ac48047ae0d00e73527dc3a3ac7fa96d16e8 Mon Sep 17 00:00:00 2001 From: Kaustubh Maske Patil <37668193+nikochiko@users.noreply.github.com> Date: Tue, 17 Oct 2023 05:53:13 +0530 Subject: [PATCH] redo explore page --- daras_ai_v2/all_pages.py | 79 ++++++++++++++++++++----------------- daras_ai_v2/meta_content.py | 12 ++++++ explore.py | 57 +++++++++++++++++++------- routers/root.py | 21 +++++++++- 4 files changed, 116 insertions(+), 53 deletions(-) diff --git a/daras_ai_v2/all_pages.py b/daras_ai_v2/all_pages.py index 85047e770..965197d3b 100644 --- a/daras_ai_v2/all_pages.py +++ b/daras_ai_v2/all_pages.py @@ -35,44 +35,49 @@ from recipes.embeddings_page import EmbeddingsPage # note: the ordering here matters! +all_home_pages_by_category = { + "Featured": [ + VideoBotsPage, + DeforumSDPage, + QRCodeGeneratorPage, + ], + "Marketing & SEO": [ + RelatedQnAPage, + SEOSummaryPage, + GoogleGPTPage, + SocialLookupEmailPage, + ], + "LLMs, RAG, & Synthetic Data": [ + BulkRunnerPage, + DocExtractPage, + CompareLLMPage, + DocSearchPage, + SmartGPTPage, + DocSummaryPage, + ], + "Videos, Lipsync, & Speech": [ + LipsyncPage, + LipsyncTTSPage, + TextToSpeechPage, + AsrPage, + Text2AudioPage, + ], + "Images": [ + Img2ImgPage, + CompareText2ImgPage, + ObjectInpaintingPage, + FaceInpaintingPage, + EmailFaceInpaintingPage, + GoogleImageGenPage, + ImageSegmentationPage, + CompareUpscalerPage, + ], +} + all_home_pages = [ - # top ones - VideoBotsPage, - DeforumSDPage, - QRCodeGeneratorPage, - # SEO tools - GoogleGPTPage, - SEOSummaryPage, - RelatedQnAPage, - # Image Tools - ObjectInpaintingPage, - CompareText2ImgPage, - Img2ImgPage, - # More Image - FaceInpaintingPage, - EmailFaceInpaintingPage, - GoogleImageGenPage, - # LipSync fun - TextToSpeechPage, - LipsyncPage, - LipsyncTTSPage, - # Text - CompareLLMPage, - DocSearchPage, - SmartGPTPage, - # Speech & Music - AsrPage, - # VideoPlayList, - Text2AudioPage, - # Other - DocSummaryPage, - RelatedQnADocPage, - SocialLookupEmailPage, - # More - ImageSegmentationPage, - CompareUpscalerPage, - DocExtractPage, - BulkRunnerPage, + page + for page_group in all_home_pages_by_category.values() + for page in page_group ] # exposed as API diff --git a/daras_ai_v2/meta_content.py b/daras_ai_v2/meta_content.py index ca8e6b483..797b9faf0 100644 --- a/daras_ai_v2/meta_content.py +++ b/daras_ai_v2/meta_content.py @@ -31,6 +31,18 @@ def build_meta_tags( ) image = meta_preview_url(page.preview_image(state), page.fallback_preivew_image()) + return raw_build_meta_tags( + url=url, title=title, description=description, image=image, + ) + + +def raw_build_meta_tags( + *, + url: str, + title: str, + description: str | None = None, + image: str | None = None, +) -> list[dict[str, str]]: ret = [ dict(title=title), dict(name="title", content=title), diff --git a/explore.py b/explore.py index edfdee9dc..66894d33f 100644 --- a/explore.py +++ b/explore.py @@ -1,23 +1,52 @@ import gooey_ui as gui from daras_ai.image_input import truncate_text_words -from daras_ai_v2.all_pages import all_home_pages +from daras_ai_v2.all_pages import all_home_pages_by_category from daras_ai_v2.grid_layout_widget import grid_layout -def render(): - def _render(page_cls): - page = page_cls() - state = page.recipe_doc_sr().to_dict() +def get_render_fn(title: str, description: str): + def render(): + def _render(page_cls): + page = page_cls() + state = page.recipe_doc_sr().to_dict() - with gui.link(to=page.app_url()): - gui.markdown(f"## {page.title}") + with gui.link(to=page.app_url()): + gui.markdown(f"### {page.title}") - preview = page.preview_description(state) - if preview: - gui.write(truncate_text_words(preview, 150)) - else: - page.render_description() + preview = page.preview_description(state) + if preview: + gui.write(truncate_text_words(preview, 150)) + else: + page.render_description() - page.render_example(state) + page.render_example(state) - grid_layout(3, all_home_pages, _render) + heading(title=title, description=description) + for category, pages in all_home_pages_by_category.items(): + separator() + section_heading(category) + grid_layout(3, pages, _render, separator=False) + + return render + + +def heading(title: str, description: str, margin_top: str = "2rem", margin_bottom: str ="2rem"): + with gui.tag( + "div", style={"margin-top": margin_top, "margin-bottom": margin_bottom} + ): + with gui.tag("p", style={"margin-top": "0rem", "margin-bottom": "0rem"}, className="text-muted"): + gui.html(description.upper()) + with gui.tag("h1", style={"margin-top": "0px", "margin-bottom": "0px", "font-weight": "500"}): + gui.html(title) + + +def section_heading(title: str, margin_top: str = "1rem", margin_bottom: str = "1rem"): + with gui.tag("h5", style={"font-weight": "600", "margin-top": margin_top, "margin-bottom": margin_bottom}): + with gui.tag("span", style={"background-color": "yellow"}): + gui.html(title.upper()) + + +def separator(*, style: dict[str, str] | None = None): + style = style or {} + style_html = "".join([f"{kv[0]}: {kv[1]};" for kv in style.items()]) + gui.html(f"""