Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: apply several small code improvements #186

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions runner/app/routes/audio_to_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def handle_pipeline_error(e: Exception) -> JSONResponse:
content=http_error(error_message),
)


# TODO: Make model_id and other None properties optional once Go codegen tool supports
# OAPI 3.1 https://github.com/deepmap/oapi-codegen/issues/373.
@router.post(
"/audio-to-text",
response_model=TextResponse,
Expand All @@ -61,7 +62,10 @@ def handle_pipeline_error(e: Exception) -> JSONResponse:
)
async def audio_to_text(
audio: Annotated[
UploadFile, File(description="Uploaded audio file to be transcribed.")
UploadFile,
File(
description="Uploaded audio file to be transcribed.", media_type="audio/*"
),
],
model_id: Annotated[
str,
Expand Down
7 changes: 5 additions & 2 deletions runner/app/routes/image_to_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


# TODO: Make model_id and other None properties optional once Go codegen tool supports
# OAPI 3.1 https://github.com/deepmap/oapi-codegen/issues/373
# OAPI 3.1 https://github.com/deepmap/oapi-codegen/issues/373.
@router.post(
"/image-to-image",
response_model=ImageResponse,
Expand All @@ -46,7 +46,10 @@ async def image_to_image(
],
image: Annotated[
UploadFile,
File(description="Uploaded image to modify with the pipeline."),
File(
description="Uploaded image to modify with the pipeline.",
media_type="image/*",
),
],
model_id: Annotated[
str,
Expand Down
6 changes: 4 additions & 2 deletions runner/app/routes/image_to_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


# TODO: Make model_id and other None properties optional once Go codegen tool supports
# OAPI 3.1 https://github.com/deepmap/oapi-codegen/issues/373
# OAPI 3.1 https://github.com/deepmap/oapi-codegen/issues/373.
@router.post(
"/image-to-video",
response_model=VideoResponse,
Expand All @@ -41,7 +41,9 @@
async def image_to_video(
image: Annotated[
UploadFile,
File(description="Uploaded image to generate a video from."),
File(
description="Uploaded image to generate a video from.", media_type="image/*"
),
],
model_id: Annotated[
str, Form(description="Hugging Face model ID used for video generation.")
Expand Down
2 changes: 1 addition & 1 deletion runner/app/routes/text_to_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

class TextToImageParams(BaseModel):
# TODO: Make model_id and other None properties optional once Go codegen tool
# supports OAPI 3.1 https://github.com/deepmap/oapi-codegen/issues/373
# supports OAPI 3.1 https://github.com/deepmap/oapi-codegen/issues/373.
model_id: Annotated[
str,
Field(
Expand Down
7 changes: 5 additions & 2 deletions runner/app/routes/upscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


# TODO: Make model_id and other None properties optional once Go codegen tool supports
# OAPI 3.1 https://github.com/deepmap/oapi-codegen/issues/373
# OAPI 3.1 https://github.com/deepmap/oapi-codegen/issues/373.
@router.post(
"/upscale",
response_model=ImageResponse,
Expand All @@ -46,7 +46,10 @@ async def upscale(
],
image: Annotated[
UploadFile,
File(description="Uploaded image to modify with the pipeline."),
File(
description="Uploaded image to modify with the pipeline.",
media_type="image/*",
),
],
model_id: Annotated[
str,
Expand Down
4 changes: 4 additions & 0 deletions worker/multipart.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func NewImageToImageMultipartWriter(w io.Writer, req ImageToImageMultipartReques
return nil, fmt.Errorf("failed to copy image to multipart request imageBytes=%v copiedBytes=%v", imageSize, copied)
}

// Handle input fields.
if err := mw.WriteField("prompt", req.Prompt); err != nil {
return nil, err
}
Expand Down Expand Up @@ -107,6 +108,7 @@ func NewImageToVideoMultipartWriter(w io.Writer, req ImageToVideoMultipartReques
return nil, fmt.Errorf("failed to copy image to multipart request imageBytes=%v copiedBytes=%v", imageSize, copied)
}

// Handle input fields.
if req.ModelId != nil {
if err := mw.WriteField("model_id", *req.ModelId); err != nil {
return nil, err
Expand Down Expand Up @@ -179,6 +181,7 @@ func NewUpscaleMultipartWriter(w io.Writer, req UpscaleMultipartRequestBody) (*m
return nil, fmt.Errorf("failed to copy image to multipart request imageBytes=%v copiedBytes=%v", imageSize, copied)
}

// Handle input fields.
if err := mw.WriteField("prompt", req.Prompt); err != nil {
return nil, err
}
Expand Down Expand Up @@ -228,6 +231,7 @@ func NewAudioToTextMultipartWriter(w io.Writer, req AudioToTextMultipartRequestB
return nil, fmt.Errorf("failed to copy audio to multipart request audioBytes=%v copiedBytes=%v", audioSize, copied)
}

// Handle input fields.
if req.ModelId != nil {
if err := mw.WriteField("model_id", *req.ModelId); err != nil {
return nil, err
Expand Down