Skip to content

Commit

Permalink
add url validation on all recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
devxpy committed Feb 29, 2024
1 parent e168d7d commit 9d3935a
Show file tree
Hide file tree
Showing 18 changed files with 83 additions and 60 deletions.
11 changes: 6 additions & 5 deletions recipes/BulkRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import typing
import uuid

import pydantic
from furl import furl
from pydantic import BaseModel, Field

Expand Down Expand Up @@ -33,15 +34,15 @@ class BulkRunnerPage(BasePage):
price = 1

class RequestModel(BaseModel):
documents: list[str] = Field(
documents: list[pydantic.AnyHttpUrl] = Field(
title="Input Data Spreadsheet",
description="""
Upload or link to a CSV or google sheet that contains your sample input data.
For example, for Copilot, this would sample questions or for Art QR Code, would would be pairs of image descriptions and URLs.
Remember to includes header names in your CSV too.
""",
)
run_urls: list[str] = Field(
run_urls: list[pydantic.AnyHttpUrl] = Field(
title="Gooey Workflows",
description="""
Provide one or more Gooey.AI workflow runs.
Expand All @@ -62,17 +63,17 @@ class RequestModel(BaseModel):
""",
)

eval_urls: list[str] | None = Field(
eval_urls: list[pydantic.AnyHttpUrl] | None = Field(
title="Evaluation Workflows",
description="""
_(optional)_ Add one or more Gooey.AI Evaluator Workflows to evaluate the results of your runs.
""",
)

class ResponseModel(BaseModel):
output_documents: list[str]
output_documents: list[pydantic.AnyHttpUrl]

eval_runs: list[str] | None = Field(
eval_runs: list[pydantic.AnyHttpUrl] | None = Field(
title="Evaluation Run URLs",
description="""
List of URLs to the evaluation runs that you requested.
Expand Down
4 changes: 3 additions & 1 deletion recipes/CompareText2Img.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import typing

import pydantic
from pydantic import BaseModel

import gooey_ui as st
Expand Down Expand Up @@ -74,7 +75,8 @@ class RequestModel(BaseModel):

class ResponseModel(BaseModel):
output_images: dict[
typing.Literal[tuple(e.name for e in Text2ImgModels)], list[str]
typing.Literal[tuple(e.name for e in Text2ImgModels)],
list[pydantic.AnyHttpUrl],
]

@classmethod
Expand Down
7 changes: 5 additions & 2 deletions recipes/CompareUpscaler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import typing

import pydantic
from pydantic import BaseModel

import gooey_ui as st
Expand All @@ -20,7 +21,7 @@ class CompareUpscalerPage(BasePage):
slug_versions = ["compare-ai-upscalers"]

class RequestModel(BaseModel):
input_image: str
input_image: pydantic.AnyHttpUrl

scale: int

Expand All @@ -29,7 +30,9 @@ class RequestModel(BaseModel):
)

class ResponseModel(BaseModel):
output_images: dict[typing.Literal[tuple(e.name for e in UpscalerModels)], str]
output_images: dict[
typing.Literal[tuple(e.name for e in UpscalerModels)], pydantic.AnyHttpUrl
]

def render_form_v2(self):
st.file_uploader(
Expand Down
3 changes: 2 additions & 1 deletion recipes/DeforumSD.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import typing
import uuid

import pydantic
from django.db.models import TextChoices
from pydantic import BaseModel
from typing_extensions import TypedDict
Expand Down Expand Up @@ -198,7 +199,7 @@ class RequestModel(BaseModel):
seed: int | None

class ResponseModel(BaseModel):
output_video: str
output_video: pydantic.AnyHttpUrl

def preview_image(self, state: dict) -> str | None:
return DEFAULT_DEFORUMSD_META_IMG
Expand Down
7 changes: 4 additions & 3 deletions recipes/DocExtract.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import threading
import typing

import pydantic
import requests
from aifail import retry_if
from django.db.models import IntegerChoices
Expand Down Expand Up @@ -68,14 +69,14 @@ class DocExtractPage(BasePage):
price = 500

class RequestModel(BaseModel):
documents: list[str]
documents: list[pydantic.AnyHttpUrl]

sheet_url: str | None
sheet_url: pydantic.AnyHttpUrl | None

selected_asr_model: typing.Literal[tuple(e.name for e in AsrModels)] | None
# language: str | None
google_translate_target: str | None
glossary_document: str | None
glossary_document: pydantic.AnyHttpUrl | None

task_instructions: str | None

Expand Down
3 changes: 2 additions & 1 deletion recipes/DocSummary.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import typing
from enum import Enum

import pydantic
from pydantic import BaseModel

import gooey_ui as st
Expand Down Expand Up @@ -55,7 +56,7 @@ class DocSummaryPage(BasePage):
}

class RequestModel(BaseModel):
documents: list[str]
documents: list[pydantic.AnyHttpUrl]

task_instructions: str | None
merge_instructions: str | None
Expand Down
11 changes: 6 additions & 5 deletions recipes/EmailFaceInpainting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import typing

import glom
import pydantic
import requests
from pydantic import BaseModel

Expand Down Expand Up @@ -81,11 +82,11 @@ class Config:
}

class ResponseModel(BaseModel):
input_image: str
resized_image: str
face_mask: str
diffusion_images: list[str]
output_images: list[str]
input_image: pydantic.AnyHttpUrl
resized_image: pydantic.AnyHttpUrl
face_mask: pydantic.AnyHttpUrl
diffusion_images: list[pydantic.AnyHttpUrl]
output_images: list[pydantic.AnyHttpUrl]
email_sent: bool = False

@classmethod
Expand Down
11 changes: 6 additions & 5 deletions recipes/FaceInpainting.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import typing
from functools import partial

import pydantic
import requests
from pydantic import BaseModel

Expand Down Expand Up @@ -44,7 +45,7 @@ class FaceInpaintingPage(BasePage):
}

class RequestModel(BaseModel):
input_image: str
input_image: pydantic.AnyHttpUrl
text_prompt: str

face_scale: float | None
Expand Down Expand Up @@ -75,10 +76,10 @@ class Config:
}

class ResponseModel(BaseModel):
resized_image: str
face_mask: str
diffusion_images: list[str]
output_images: list[str]
resized_image: pydantic.AnyHttpUrl
face_mask: pydantic.AnyHttpUrl
diffusion_images: list[pydantic.AnyHttpUrl]
output_images: list[pydantic.AnyHttpUrl]

def preview_image(self, state: dict) -> str | None:
return DEFAULT_FACE_INPAINTING_META_IMG
Expand Down
11 changes: 6 additions & 5 deletions recipes/ImageSegmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import PIL
import numpy as np
import pydantic
import requests
import gooey_ui as st
from pydantic import BaseModel
Expand Down Expand Up @@ -47,7 +48,7 @@ class ImageSegmentationPage(BasePage):
}

class RequestModel(BaseModel):
input_image: str
input_image: pydantic.AnyHttpUrl

selected_model: (
typing.Literal[tuple(e.name for e in ImageSegmentationModels)] | None
Expand All @@ -62,10 +63,10 @@ class RequestModel(BaseModel):
obj_pos_y: float | None

class ResponseModel(BaseModel):
output_image: str
cutout_image: str
resized_image: str
resized_mask: str
output_image: pydantic.AnyHttpUrl
cutout_image: pydantic.AnyHttpUrl
resized_image: pydantic.AnyHttpUrl
resized_mask: pydantic.AnyHttpUrl

def preview_image(self, state: dict) -> str | None:
return DEFAULT_IMG_SEGMENTATION_META_IMG
Expand Down
5 changes: 3 additions & 2 deletions recipes/Img2Img.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import typing

import pydantic
import requests
from pydantic import BaseModel

Expand Down Expand Up @@ -42,7 +43,7 @@ class Img2ImgPage(BasePage):
}

class RequestModel(BaseModel):
input_image: str
input_image: pydantic.AnyHttpUrl
text_prompt: str | None

selected_model: typing.Literal[tuple(e.name for e in Img2ImgModels)] | None
Expand Down Expand Up @@ -70,7 +71,7 @@ class RequestModel(BaseModel):
image_guidance_scale: float | None

class ResponseModel(BaseModel):
output_images: list[str]
output_images: list[pydantic.AnyHttpUrl]

@classmethod
def get_example_preferred_fields(self, state: dict) -> list[str]:
Expand Down
8 changes: 5 additions & 3 deletions recipes/Lipsync.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import typing
from pathlib import Path
import urllib.request

import pydantic
import requests

from pydantic import BaseModel
Expand All @@ -25,16 +27,16 @@ class LipsyncPage(BasePage):
slug_versions = ["Lipsync"]

class RequestModel(BaseModel):
input_face: str
input_audio: str
input_face: pydantic.AnyHttpUrl
input_audio: pydantic.AnyHttpUrl

face_padding_top: int | None
face_padding_bottom: int | None
face_padding_left: int | None
face_padding_right: int | None

class ResponseModel(BaseModel):
output_video: str
output_video: pydantic.AnyHttpUrl

def preview_image(self, state: dict) -> str | None:
return DEFAULT_LIPSYNC_META_IMG
Expand Down
7 changes: 4 additions & 3 deletions recipes/LipsyncTTS.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import typing

import pydantic
from pydantic import BaseModel

import gooey_ui as st
Expand All @@ -26,8 +27,8 @@ class LipsyncTTSPage(LipsyncPage, TextToSpeechPage):
}

class RequestModel(BaseModel):
input_face: str
input_audio: str | None
input_face: pydantic.AnyHttpUrl
input_audio: pydantic.AnyHttpUrl | None

face_padding_top: int | None
face_padding_bottom: int | None
Expand Down Expand Up @@ -57,7 +58,7 @@ class RequestModel(BaseModel):
elevenlabs_speaker_boost: bool | None

class ResponseModel(BaseModel):
output_video: str
output_video: pydantic.AnyHttpUrl

def related_workflows(self) -> list:
from recipes.VideoBots import VideoBotsPage
Expand Down
11 changes: 6 additions & 5 deletions recipes/ObjectInpainting.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import typing

import pydantic
import requests
from pydantic import BaseModel

Expand Down Expand Up @@ -45,7 +46,7 @@ class ObjectInpaintingPage(BasePage):
}

class RequestModel(BaseModel):
input_image: str
input_image: pydantic.AnyHttpUrl
text_prompt: str

obj_scale: float | None
Expand All @@ -71,10 +72,10 @@ class RequestModel(BaseModel):
seed: int | None

class ResponseModel(BaseModel):
resized_image: str
obj_mask: str
# diffusion_images: list[str]
output_images: list[str]
resized_image: pydantic.AnyHttpUrl
obj_mask: pydantic.AnyHttpUrl
# diffusion_images: list[pydantic.AnyHttpUrl]
output_images: list[pydantic.AnyHttpUrl]

def preview_image(self, state: dict) -> str | None:
return DEFAULT_OBJECT_INPAINTING_META_IMG
Expand Down
13 changes: 7 additions & 6 deletions recipes/QRCodeGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from enum import Enum

import numpy as np
import pydantic
import qrcode
import requests
from django.core.exceptions import ValidationError
Expand Down Expand Up @@ -79,9 +80,9 @@ def __init__(self, *args, **kwargs):

class RequestModel(BaseModel):
qr_code_data: str | None
qr_code_input_image: str | None
qr_code_input_image: pydantic.AnyHttpUrl | None
qr_code_vcard: VCARD | None
qr_code_file: str | None
qr_code_file: pydantic.AnyHttpUrl | None

use_url_shortener: bool | None

Expand Down Expand Up @@ -118,10 +119,10 @@ class RequestModel(BaseModel):
obj_pos_y: float | None

class ResponseModel(BaseModel):
output_images: list[str]
raw_images: list[str]
shortened_url: str | None
cleaned_qr_code: str
output_images: list[pydantic.AnyHttpUrl]
raw_images: list[pydantic.AnyHttpUrl]
shortened_url: pydantic.AnyHttpUrl | None
cleaned_qr_code: pydantic.AnyHttpUrl

def preview_image(self, state: dict) -> str | None:
if len(state.get("output_images") or []) > 0:
Expand Down
Loading

0 comments on commit 9d3935a

Please sign in to comment.