Skip to content

Commit

Permalink
fix(pipelines): fix image truncation bug when seed is set (#77)
Browse files Browse the repository at this point in the history
This commit ensure that all images are returned when a seed is set in
the old code only the fist image of the badge was returned.
  • Loading branch information
rickstaa committed May 6, 2024
1 parent 792b620 commit 2f8ab8a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
14 changes: 7 additions & 7 deletions runner/app/routes/image_to_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
responses = {400: {"model": HTTPError}, 500: {"model": HTTPError}}


# TODO: Make model_id optional once Go codegen tool supports OAPI 3.1
# https://github.com/deepmap/oapi-codegen/issues/373
# TODO: Make model_id and other properties optional once Go codegen tool supports
# OAPI 3.1 https://github.com/deepmap/oapi-codegen/issues/373
@router.post("/image-to-image", response_model=ImageResponse, responses=responses)
@router.post(
"/image-to-image/",
Expand Down Expand Up @@ -61,11 +61,11 @@ async def image_to_image(
)

if seed is None:
init_seed = random.randint(0, 2**32 - 1)
if num_images_per_prompt > 1:
seed = [i for i in range(init_seed, init_seed + num_images_per_prompt)]
else:
seed = init_seed
seed = random.randint(0, 2**32 - 1)
if num_images_per_prompt > 1:
seed = [
i for i in range(seed, seed + num_images_per_prompt)
]

img = Image.open(image.file).convert("RGB")
# If a list of seeds/generators is passed, diffusers wants a list of images
Expand Down
4 changes: 2 additions & 2 deletions runner/app/routes/image_to_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
responses = {400: {"model": HTTPError}, 500: {"model": HTTPError}}


# TODO: Make model_id optional once Go codegen tool supports OAPI 3.1
# https://github.com/deepmap/oapi-codegen/issues/373
# TODO: Make model_id and other properties optional once Go codegen tool supports
# OAPI 3.1 https://github.com/deepmap/oapi-codegen/issues/373
@router.post("/image-to-video", response_model=VideoResponse, responses=responses)
@router.post(
"/image-to-video/",
Expand Down
16 changes: 7 additions & 9 deletions runner/app/routes/text_to_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@


class TextToImageParams(BaseModel):
# TODO: Make model_id optional once Go codegen tool supports OAPI 3.1
# https://github.com/deepmap/oapi-codegen/issues/373
# TODO: Make model_id and other properties optional once Go codegen tool supports
# OAPI 3.1 https://github.com/deepmap/oapi-codegen/issues/373
model_id: str = ""
prompt: str
height: int = None
Expand Down Expand Up @@ -56,13 +56,11 @@ async def text_to_image(
)

if params.seed is None:
init_seed = random.randint(0, 2**32 - 1)
if params.num_images_per_prompt > 1:
params.seed = [
i for i in range(init_seed, init_seed + params.num_images_per_prompt)
]
else:
params.seed = init_seed
params.seed = random.randint(0, 2**32 - 1)
if params.num_images_per_prompt > 1:
params.seed = [
i for i in range(params.seed, params.seed + params.num_images_per_prompt)
]

try:
images = pipeline(**params.model_dump())
Expand Down

0 comments on commit 2f8ab8a

Please sign in to comment.