Skip to content

Commit

Permalink
render_example: handle recipe specific media rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
anish-work committed Mar 6, 2025
1 parent 71c085c commit 2522305
Show file tree
Hide file tree
Showing 33 changed files with 239 additions and 155 deletions.
302 changes: 186 additions & 116 deletions daras_ai_v2/base.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion recipes/BulkEval.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def render_agg_inputs(key: str, del_key: str, d: AggFunction):
# def render_settings(self):
# language_model_settings()

def render_example(self, state: dict):
def render_run_preview_output(self, state: dict):
render_documents(state)

def render_output(self):
Expand Down
2 changes: 1 addition & 1 deletion recipes/BulkRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def render_form_v2(self):
flatten_dict_key="url",
)

def render_example(self, state: dict):
def render_run_preview_output(self, state: dict):
render_documents(state)

def render_output(self):
Expand Down
2 changes: 1 addition & 1 deletion recipes/ChyronPlant.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def run_chyron(self, state: dict):
return text
return ""

def render_example(self, state):
def render_run_preview_output(self, state):
col1, col2 = gui.columns(2)
with col1:
gui.write(state.get("midi_translation", ""))
Expand Down
2 changes: 1 addition & 1 deletion recipes/CompareLLM.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def run(self, state: dict) -> typing.Iterator[str | None]:
def render_output(self):
_render_outputs(gui.session_state, 450)

def render_example(self, state: dict):
def render_run_preview_output(self, state: dict):
col1, col2 = gui.columns(2)
with col1:
gui.write("**Prompt**")
Expand Down
2 changes: 1 addition & 1 deletion recipes/CompareText2Img.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def run(self, state: dict) -> typing.Iterator[str | None]:
)
]

def render_example(self, state: dict):
def render_run_preview_output(self, state: dict):
col1, col2 = gui.columns(2)
with col1:
gui.markdown("```properties\n" + state.get("text_prompt", "") + "\n```")
Expand Down
2 changes: 1 addition & 1 deletion recipes/CompareUpscaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def render_description(self):
def render_output(self):
_render_outputs(gui.session_state)

def render_example(self, state: dict):
def render_run_preview_output(self, state: dict):
col1, col2 = gui.columns(2)
with col1:
gui.image(state.get("input_image"), caption="Input Image")
Expand Down
5 changes: 4 additions & 1 deletion recipes/DeforumSD.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,15 @@ def estimate_run_duration(self):
# in seconds
return gui.session_state.get("max_frames", 100) * MODEL_ESTIMATED_TIME_PER_FRAME

def render_example(self, state: dict):
def render_run_preview_output(self, state: dict):
display = self.preview_input(state)
gui.markdown("```lua\n" + display + "\n```")

gui.video(state.get("output_video"), autoplay=True)

def render_example_preview_media(self, published_run: dict):
gui.video(published_run.saved_run.state.get("output_video"))

@classmethod
def preview_input(cls, state: dict) -> str:
input_prompt = state.get("input_prompt")
Expand Down
2 changes: 1 addition & 1 deletion recipes/DocExtract.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def validate_form_v2(self):
def preview_description(self, state: dict) -> str:
return "Transcribe YouTube videos in any language with Whisper, Google Chirp & more, run your own GPT4 prompt on each transcript and save it all to a Google Sheet. Perfect for making a YouTube-based dataset to create your own chatbot or enterprise copilot (ie. just add the finished Google sheet url to the doc section in https://gooey.ai/copilot)."

def render_example(self, state: dict):
def render_run_preview_output(self, state: dict):
if sheet_url := state.get("sheet_url"):
render_documents(state, label="**Input Documents**")
gui.write("**Google Sheets URL**")
Expand Down
2 changes: 1 addition & 1 deletion recipes/DocSearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def render_output(self):
refs = gui.session_state.get("references", [])
render_sources_widget(refs)

def render_example(self, state: dict):
def render_run_preview_output(self, state: dict):
render_documents(state)
gui.html("**Search Query**")
gui.write("```properties\n" + state.get("search_query", "") + "\n```")
Expand Down
2 changes: 1 addition & 1 deletion recipes/DocSummary.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def validate_form_v2(self):
def render_output(self):
render_output_with_refs(gui.session_state)

def render_example(self, state: dict):
def render_run_preview_output(self, state: dict):
render_documents(state)
gui.write("**Instructions**")
gui.write("```properties\n" + state.get("task_instructions", "") + "\n```")
Expand Down
2 changes: 1 addition & 1 deletion recipes/EmailFaceInpainting.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def _get_email_body(

return email_body

def render_example(self, state: dict):
def render_run_preview_output(self, state: dict):
if state.get("email_address"):
gui.write("**Input Email** -", state.get("email_address"))
elif state.get("twitter_handle"):
Expand Down
2 changes: 1 addition & 1 deletion recipes/FaceInpainting.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def related_workflows(self) -> list:
SEOSummaryPage,
]

def render_example(self, state: dict):
def render_run_preview_output(self, state: dict):
col1, col2 = gui.columns(2)
with col2:
output_images = state.get("output_images")
Expand Down
2 changes: 1 addition & 1 deletion recipes/GoogleGPT.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def render_output(self):
refs = gui.session_state.get("references", [])
render_sources_widget(refs)

def render_example(self, state: dict):
def render_run_preview_output(self, state: dict):
gui.write("**Search Query**")
gui.write("```properties\n" + state.get("search_query", "") + "\n```")
site_filter = state.get("site_filter")
Expand Down
2 changes: 1 addition & 1 deletion recipes/GoogleImageGen.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def render_steps(self):
else:
gui.div()

def render_example(self, state: dict):
def render_run_preview_output(self, state: dict):
gui.write(
f"""
**Google Search Query** `{state.get("search_query", '')}` \\
Expand Down
4 changes: 2 additions & 2 deletions recipes/ImageSegmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def run(self, state: dict) -> typing.Iterator[str | None]:
yield

def render_output(self):
self.render_example(gui.session_state)
self.render_run_preview_output(gui.session_state)

def render_steps(self):
col1, col2, col3, col4 = gui.columns(4)
Expand Down Expand Up @@ -337,7 +337,7 @@ def render_steps(self):
else:
gui.div()

def render_example(self, state: dict):
def render_run_preview_output(self, state: dict):
col1, col2 = gui.columns(2)

with col1:
Expand Down
12 changes: 10 additions & 2 deletions recipes/Img2Img.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pydantic import BaseModel

import gooey_gui as gui
from bots.models import Workflow
from bots.models import PublishedRun, Workflow
from daras_ai_v2.base import BasePage
from daras_ai_v2.img_model_settings_widgets import img_model_settings
from daras_ai_v2.loom_video_widget import youtube_video
Expand Down Expand Up @@ -137,7 +137,7 @@ def render_output(self):
for img in output_images:
gui.image(img, show_download_button=True)

def render_example(self, state: dict):
def render_run_preview_output(self, state: dict):
col1, col2 = gui.columns(2)
with col2:
output_images = state.get("output_images", [])
Expand All @@ -149,6 +149,14 @@ def render_example(self, state: dict):
gui.write("**Prompt**")
gui.write("```properties\n" + state.get("text_prompt", "") + "\n```")

def render_example_preview_media(self, published_run: PublishedRun):
state = published_run.saved_run.state
input_image = state.get("input_image", None)
output_images = state.get("output_images", [])
with gui.div(className="d-flex gap-2"):
gui.image(input_image)
gui.image(output_images[0])

def run(self, state: dict) -> typing.Iterator[str | None]:
request: Img2ImgPage.RequestModel = self.RequestModel.parse_obj(state)

Expand Down
4 changes: 2 additions & 2 deletions recipes/Lipsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def run(self, state: dict) -> typing.Iterator[str | None]:
max_frames=max_frames,
)

def render_example(self, state: dict):
def render_run_preview_output(self, state: dict):
output_video = state.get("output_video")
if output_video:
gui.write("#### Output Video")
Expand All @@ -115,7 +115,7 @@ def render_example(self, state: dict):
gui.div()

def render_output(self):
self.render_example(gui.session_state)
self.render_run_preview_output(gui.session_state)

def related_workflows(self) -> list:
from recipes.DeforumSD import DeforumSDPage
Expand Down
4 changes: 2 additions & 2 deletions recipes/LipsyncTTS.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def run(self, state: dict) -> typing.Iterator[str | None]:
state["input_audio"] = state["audio_url"]
yield from LipsyncPage(request=self.request).run(state)

def render_example(self, state: dict):
def render_run_preview_output(self, state: dict):
output_video = state.get("output_video")
if output_video:
gui.video(
Expand All @@ -140,7 +140,7 @@ def render_example(self, state: dict):
gui.div()

def render_output(self):
self.render_example(gui.session_state)
self.render_run_preview_output(gui.session_state)

def get_raw_price(self, state: dict):
# _get_tts_provider comes from TextToSpeechPage
Expand Down
2 changes: 1 addition & 1 deletion recipes/ObjectInpainting.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def run(self, state: dict):
)
state["output_images"] = diffusion_images

def render_example(self, state: dict):
def render_run_preview_output(self, state: dict):
col1, col2 = gui.columns(2)
with col2:
output_images = state.get("output_images")
Expand Down
9 changes: 7 additions & 2 deletions recipes/QRCodeGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import gooey_gui as gui
from app_users.models import AppUser
from bots.models import Workflow
from bots.models import PublishedRun, Workflow
from daras_ai.image_input import (
upload_file_from_bytes,
bytes_to_cv2_img,
Expand Down Expand Up @@ -438,7 +438,12 @@ def render_output(self):
state = gui.session_state
self._render_outputs(state)

def render_example(self, state: dict):
def render_example_preview_media(self, published_run: PublishedRun):
output_images = list(published_run.saved_run.state.get("output_images", []))
if output_images:
gui.image(output_images[0])

def render_run_preview_output(self, state: dict):
self._render_outputs(state, max_count=1)

def _render_outputs(self, state: dict, max_count: int | None = None):
Expand Down
2 changes: 1 addition & 1 deletion recipes/RelatedQnA.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def render_steps(self):
def render_output(self):
render_qna_outputs(gui.session_state, 300)

def render_example(self, state: dict):
def render_run_preview_output(self, state: dict):
gui.write("**Search Query**")
gui.write("```properties\n" + state.get("search_query", "") + "\n```")
site_filter = state.get("site_filter")
Expand Down
2 changes: 1 addition & 1 deletion recipes/RelatedQnADoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def validate_form_v2(self):
def render_output(self):
render_qna_outputs(gui.session_state)

def render_example(self, state: dict):
def render_run_preview_output(self, state: dict):
gui.write("**Search Query**")
gui.write("```properties\n" + state.get("search_query", "") + "\n```")
site_filter = state.get("site_filter")
Expand Down
2 changes: 1 addition & 1 deletion recipes/SEOSummary.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def render_steps(self):
else:
gui.div()

def render_example(self, state: dict):
def render_run_preview_output(self, state: dict):
gui.write(
f"""
Search Query `{state.get('search_query', '')}` \\
Expand Down
2 changes: 1 addition & 1 deletion recipes/SmartGPT.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def run(self, state: dict) -> typing.Iterator[str | None]:
def render_output(self):
render_output_with_refs(gui.session_state)

def render_example(self, state: dict):
def render_run_preview_output(self, state: dict):
gui.write("**Prompt**")
gui.write("```properties\n" + state.get("input_prompt", "") + "\n```")
render_output_with_refs(state, 200)
Expand Down
2 changes: 1 addition & 1 deletion recipes/SocialLookupEmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def render_steps(self):
else:
gui.div()

def render_example(self, state: dict):
def render_run_preview_output(self, state: dict):
gui.write("**Email Address**")
gui.write(state.get("email_address", ""))
gui.write("**Email Body Output**")
Expand Down
2 changes: 1 addition & 1 deletion recipes/Text2Audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def run(self, state: dict) -> typing.Iterator[str | None]:
def render_output(self):
_render_output(gui.session_state)

def render_example(self, state: dict):
def render_run_preview_output(self, state: dict):
col1, col2 = gui.columns(2)
with col1:
gui.markdown("```properties\n" + state.get("text_prompt", "") + "\n```")
Expand Down
2 changes: 1 addition & 1 deletion recipes/TextToSpeech.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ def related_workflows(self) -> list:
CompareText2ImgPage,
]

def render_example(self, state: dict):
def render_run_preview_output(self, state: dict):
col1, col2 = gui.columns(2)
with col1:
text = state.get("text_prompt")
Expand Down
2 changes: 1 addition & 1 deletion recipes/Translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def validate_form_v2(self):
def render_output(self):
text_outputs("**Translations**", key="output_texts", height=300)

def render_example(self, state: dict):
def render_run_preview_output(self, state: dict):
text_outputs("**Translations**", value=state.get("output_texts", []))

def render_steps(self):
Expand Down
2 changes: 1 addition & 1 deletion recipes/VideoBots.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ def run_as_api_tab(self):
def get_example_preferred_fields(cls, state: dict) -> list[str]:
return ["input_prompt", "messages"]

def render_example(self, state: dict):
def render_run_preview_output(self, state: dict):
input_prompt = state.get("input_prompt")
if input_prompt:
gui.write(
Expand Down
2 changes: 1 addition & 1 deletion recipes/asr_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def validate_form_v2(self):
def render_output(self):
text_outputs("**Transcription**", key="output_text", height=300)

def render_example(self, state: dict):
def render_run_preview_output(self, state: dict):
render_documents(state)
text_outputs("**Transcription**", value=state.get("output_text"))

Expand Down
2 changes: 1 addition & 1 deletion recipes/embeddings_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def render_output(self):
gui.write(f"##### `embeddings[{i}]`")
gui.json(embedding, depth=0)

def render_example(self, state: dict):
def render_run_preview_output(self, state: dict):
texts = gui.session_state.setdefault("texts", [""])
for i, text in enumerate(texts):
texts[i] = gui.text_area(f"`texts[{i}]`", value=text, disabled=True)
Expand Down
4 changes: 1 addition & 3 deletions routers/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,7 @@ def _render_run(pr: PublishedRun):
workflow = Workflow(pr.workflow)
visibility = PublishedRunVisibility(pr.visibility)

workflow.page_cls().render_published_run_full_width(
pr, workflow_pill=workflow.short_title
)
workflow.page_cls().render_example(pr, workflow_pill=workflow.short_title)

gui.write("# Saved Workflows")
explore_path = get_route_path(explore_page)
Expand Down

0 comments on commit 2522305

Please sign in to comment.