Skip to content

Commit

Permalink
use BasePage.RequestModel as the base model for all recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
devxpy committed Jul 3, 2024
1 parent c4053bc commit ad6851c
Show file tree
Hide file tree
Showing 28 changed files with 35 additions and 34 deletions.
2 changes: 1 addition & 1 deletion recipes/BulkEval.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def related_workflows(self) -> list:

return [BulkRunnerPage, VideoBotsPage, AsrPage, DocSearchPage]

class RequestModel(LLMSettingsMixin, BaseModel):
class RequestModel(LLMSettingsMixin, BasePage.RequestModel):
documents: list[str] = Field(
title="Input Data Spreadsheet",
description="""
Expand Down
6 changes: 3 additions & 3 deletions recipes/BulkRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class BulkRunnerPage(BasePage):
slug_versions = ["bulk-runner", "bulk"]
price = 1

class RequestModel(BaseModel):
class RequestModel(BasePage.RequestModel):
documents: list[FieldHttpUrl] = Field(
title="Input Data Spreadsheet",
description="""
Expand Down Expand Up @@ -426,7 +426,7 @@ def render_description(self):
def render_run_url_inputs(self, key: str, del_key: str, d: dict):
from daras_ai_v2.all_pages import all_home_pages

added_options = init_workflow_selector(d, key)
init_workflow_selector(d, key)

col1, col2, col3, col4 = st.columns([9, 1, 1, 1], responsive=False)
if not d.get("workflow") and d.get("url"):
Expand Down Expand Up @@ -466,7 +466,7 @@ def render_run_url_inputs(self, key: str, del_key: str, d: dict):
options = get_published_run_options(
page_cls, current_user=self.request.user
)
options.update(added_options)
options.update(d.get("--added_workflows", {}))
with st.div(className="pt-1"):
url = st.selectbox(
"",
Expand Down
2 changes: 1 addition & 1 deletion recipes/ChyronPlant.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ChyronPlantPage(BasePage):
workflow = Workflow.CHYRON_PLANT
slug_versions = ["ChyronPlant"]

class RequestModel(BaseModel):
class RequestModel(BasePage.RequestModel):
midi_notes: str

midi_notes_prompt: str | None
Expand Down
4 changes: 2 additions & 2 deletions recipes/CompareLLM.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CompareLLMPage(BasePage):
"sampling_temperature": 0.7,
}

class RequestModel(BaseModel):
class RequestModel(BasePage.RequestModel):
input_prompt: str | None
selected_models: (
list[typing.Literal[tuple(e.name for e in LargeLanguageModels)]] | None
Expand Down Expand Up @@ -141,7 +141,7 @@ def render_example(self, state: dict):
st.write("**Prompt**")
st.write("```jinja2\n" + state.get("input_prompt", "") + "\n```")
for key, value in state.get("variables", {}).items():
st.text_area(f"`{key}`", value=value, disabled=True)
st.text_area(f"`{key}`", value=str(value), disabled=True)
with col2:
_render_outputs(state, 300)

Expand Down
2 changes: 1 addition & 1 deletion recipes/CompareText2Img.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CompareText2ImgPage(BasePage):
"dall_e_3_style": "vivid",
}

class RequestModel(BaseModel):
class RequestModel(BasePage.RequestModel):
text_prompt: str
negative_prompt: str | None

Expand Down
2 changes: 1 addition & 1 deletion recipes/CompareUpscaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CompareUpscalerPage(BasePage):
workflow = Workflow.COMPARE_UPSCALER
slug_versions = ["compare-ai-upscalers"]

class RequestModel(BaseModel):
class RequestModel(BasePage.RequestModel):
input_image: FieldHttpUrl | None = Field(None, description="Input Image")
input_video: FieldHttpUrl | None = Field(None, description="Input Video")

Expand Down
2 changes: 1 addition & 1 deletion recipes/DeforumSD.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class DeforumSDPage(BasePage):
selected_model=AnimationModels.protogen_2_2.name,
)

class RequestModel(BaseModel):
class RequestModel(BasePage.RequestModel):
# input_prompt: str
animation_prompts: AnimationPrompts
max_frames: int | None
Expand Down
2 changes: 1 addition & 1 deletion recipes/DocExtract.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class DocExtractPage(BasePage):
]
price = 500

class RequestModel(BaseModel):
class RequestModel(BasePage.RequestModel):
documents: list[FieldHttpUrl]

sheet_url: FieldHttpUrl | None
Expand Down
2 changes: 1 addition & 1 deletion recipes/DocSearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class DocSearchPage(BasePage):
"dense_weight": 1.0,
}

class RequestModel(DocSearchRequest):
class RequestModel(DocSearchRequest, BasePage.RequestModel):
task_instructions: str | None
query_instructions: str | None

Expand Down
2 changes: 1 addition & 1 deletion recipes/DocSummary.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class DocSummaryPage(BasePage):
"chain_type": CombineDocumentsChains.map_reduce.name,
}

class RequestModel(BaseModel):
class RequestModel(BasePage.RequestModel):
documents: list[FieldHttpUrl]

task_instructions: str | None
Expand Down
5 changes: 3 additions & 2 deletions recipes/EmailFaceInpainting.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import re
import typing

from daras_ai_v2.pydantic_validation import FieldHttpUrl
import requests
from pydantic import BaseModel

import gooey_ui as st
from bots.models import Workflow
from daras_ai.image_input import upload_file_from_bytes
from daras_ai_v2 import db, settings
from daras_ai_v2.base import BasePage
from daras_ai_v2.exceptions import raise_for_status
from daras_ai_v2.loom_video_widget import youtube_video
from daras_ai_v2.pydantic_validation import FieldHttpUrl
from daras_ai_v2.send_email import send_email_via_postmark
from daras_ai_v2.stable_diffusion import InpaintingModels
from recipes.FaceInpainting import FaceInpaintingPage
Expand Down Expand Up @@ -38,7 +39,7 @@ class EmailFaceInpaintingPage(FaceInpaintingPage):
"twitter_handle": "seanb",
}

class RequestModel(BaseModel):
class RequestModel(BasePage.RequestModel):
email_address: str | None
twitter_handle: str | None

Expand Down
2 changes: 1 addition & 1 deletion recipes/FaceInpainting.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class FaceInpaintingPage(BasePage):
"upscale_factor": 1.0,
}

class RequestModel(BaseModel):
class RequestModel(BasePage.RequestModel):
input_image: FieldHttpUrl
text_prompt: str

Expand Down
2 changes: 1 addition & 1 deletion recipes/GoogleGPT.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class GoogleGPTPage(BasePage):
dense_weight=1.0,
)

class RequestModel(GoogleSearchMixin, BaseModel):
class RequestModel(GoogleSearchMixin, BasePage.RequestModel):
search_query: str
site_filter: str

Expand Down
2 changes: 1 addition & 1 deletion recipes/GoogleImageGen.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class GoogleImageGenPage(BasePage):
serp_search_location=SerpSearchLocation.UNITED_STATES,
)

class RequestModel(GoogleSearchLocationMixin, BaseModel):
class RequestModel(GoogleSearchLocationMixin, BasePage.RequestModel):
search_query: str
text_prompt: str

Expand Down
2 changes: 1 addition & 1 deletion recipes/ImageSegmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ImageSegmentationPage(BasePage):
"obj_pos_y": 0.5,
}

class RequestModel(BaseModel):
class RequestModel(BasePage.RequestModel):
input_image: FieldHttpUrl

selected_model: (
Expand Down
2 changes: 1 addition & 1 deletion recipes/Img2Img.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Img2ImgPage(BasePage):
"controlnet_conditioning_scale": [1.0],
}

class RequestModel(BaseModel):
class RequestModel(BasePage.RequestModel):
input_image: FieldHttpUrl
text_prompt: str | None

Expand Down
2 changes: 1 addition & 1 deletion recipes/LetterWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class LetterWriterPage(BasePage):
workflow = Workflow.LETTER_WRITER
slug_versions = ["LetterWriter"]

class RequestModel(BaseModel):
class RequestModel(BasePage.RequestModel):
action_id: str

prompt_header: str | None
Expand Down
2 changes: 1 addition & 1 deletion recipes/Lipsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class LipsyncPage(BasePage):
workflow = Workflow.LIPSYNC
slug_versions = ["Lipsync"]

class RequestModel(LipsyncSettings, BaseModel):
class RequestModel(LipsyncSettings, BasePage.RequestModel):
selected_model: typing.Literal[tuple(e.name for e in LipsyncModel)] = (
LipsyncModel.Wav2Lip.name
)
Expand Down
2 changes: 1 addition & 1 deletion recipes/ObjectInpainting.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ObjectInpaintingPage(BasePage):
"seed": 42,
}

class RequestModel(BaseModel):
class RequestModel(BasePage.RequestModel):
input_image: FieldHttpUrl
text_prompt: str

Expand Down
2 changes: 1 addition & 1 deletion recipes/QRCodeGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.__dict__.update(self.sane_defaults)

class RequestModel(BaseModel):
class RequestModel(BasePage.RequestModel):
qr_code_data: str | None
qr_code_input_image: FieldHttpUrl | None
qr_code_vcard: VCARD | None
Expand Down
2 changes: 1 addition & 1 deletion recipes/SmartGPT.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SmartGPTPage(BasePage):
slug_versions = ["SmartGPT"]
price = 20

class RequestModel(BaseModel):
class RequestModel(BasePage.RequestModel):
input_prompt: str

cot_prompt: str | None
Expand Down
2 changes: 1 addition & 1 deletion recipes/SocialLookupEmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SocialLookupEmailPage(BasePage):
"sampling_temperature": 0.5,
}

class RequestModel(BaseModel):
class RequestModel(BasePage.RequestModel):
email_address: str

input_prompt: str | None
Expand Down
2 changes: 1 addition & 1 deletion recipes/Text2Audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Text2AudioPage(BasePage):
seed=42,
)

class RequestModel(BaseModel):
class RequestModel(BasePage.RequestModel):
text_prompt: str
negative_prompt: str | None

Expand Down
2 changes: 1 addition & 1 deletion recipes/TextToSpeech.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class TextToSpeechPage(BasePage):
"openai_tts_model": "tts-1",
}

class RequestModelBase(BaseModel):
class RequestModelBase(BasePage.RequestModel):
text_prompt: str

class RequestModel(TextToSpeechSettings, RequestModelBase):
Expand Down
4 changes: 2 additions & 2 deletions recipes/Translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ class TranslationPage(BasePage):
workflow = Workflow.TRANSLATION
slug_versions = ["translate", "translation", "compare-ai-translation"]

class BaseRequestModel(BaseModel):
class RequestModelBase(BasePage.RequestModel):
texts: list[str] = Field([])

selected_model: (
typing.Literal[tuple(e.name for e in TranslationModels)]
) | None = Field(TranslationModels.google.name)

class RequestModel(TranslationOptions, BaseRequestModel):
class RequestModel(TranslationOptions, RequestModelBase):
pass

class ResponseModel(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion recipes/VideoBots.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class VideoBotsPage(BasePage):
"translation_model": TranslationModels.google.name,
}

class RequestModelBase(BaseModel):
class RequestModelBase(BasePage.RequestModel):
input_prompt: str | None
input_audio: str | None
input_images: list[FieldHttpUrl] | None
Expand Down
4 changes: 2 additions & 2 deletions recipes/asr_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AsrPage(BasePage):

sane_defaults = dict(output_format=AsrOutputFormat.text.name)

class BaseRequestModel(BaseModel):
class RequestModelBase(BasePage.RequestModel):
documents: list[FieldHttpUrl]
selected_model: typing.Literal[tuple(e.name for e in AsrModels)] | None
language: str | None
Expand All @@ -57,7 +57,7 @@ class BaseRequestModel(BaseModel):
description="use `translation_model` & `translation_target` instead.",
)

class RequestModel(TranslationOptions, BaseRequestModel):
class RequestModel(TranslationOptions, RequestModelBase):
pass

class ResponseModel(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion recipes/embeddings_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class EmbeddingsPage(BasePage):
slug_versions = ["embeddings", "embed", "text-embedings"]
price = 1

class RequestModel(BaseModel):
class RequestModel(BasePage.RequestModel):
texts: list[str]
selected_model: typing.Literal[tuple(e.name for e in EmbeddingModels)] | None

Expand Down

0 comments on commit ad6851c

Please sign in to comment.