Skip to content

Commit

Permalink
feat(api): switch inpaint mode to upscale stage
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Jan 29, 2023
1 parent 483a1ba commit 50d6dbb
Showing 1 changed file with 13 additions and 31 deletions.
44 changes: 13 additions & 31 deletions api/onnx_web/diffusion/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from PIL import Image, ImageChops
from typing import Any

from ..chain import (
upscale_outpaint,
)
from ..image import (
expand_image,
)
Expand Down Expand Up @@ -109,7 +112,7 @@ def run_inpaint_pipeline(
ctx: ServerContext,
stage: StageParams,
params: ImageParams,
size: Size,
_size: Size,
output: str,
upscale: UpscaleParams,
source_image: Image.Image,
Expand All @@ -120,39 +123,18 @@ def run_inpaint_pipeline(
strength: float,
fill_color: str,
) -> None:
pipe = load_pipeline(OnnxStableDiffusionInpaintPipeline,
params.model, params.provider, params.scheduler)

latents = get_latents_from_seed(params.seed, size)
rng = np.random.RandomState(params.seed)

logger.info('applying mask filter and generating noise source')
source_image, mask_image, noise_image, _full_dims = expand_image(
image = upscale_outpaint(
ctx,
stage,
params,
source_image,
mask_image,
expand,
fill=fill_color,
noise_source=noise_source,
mask_filter=mask_filter)

if is_debug():
source_image.save(base_join(ctx.output_path, 'last-source.png'))
mask_image.save(base_join(ctx.output_path, 'last-mask.png'))
noise_image.save(base_join(ctx.output_path, 'last-noise.png'))

result = pipe(
params.prompt,
generator=rng,
guidance_scale=params.cfg,
height=size.height,
image=source_image,
latents=latents,
border=expand,
mask_image=mask_image,
negative_prompt=params.negative_prompt,
num_inference_steps=params.steps,
width=size.width,
fill_color=fill_color,
mask_filter=mask_filter,
noise_source=noise_source,
)
image = result.images[0]
logger.info('applying mask filter and generating noise source')

if image.size == source_image.size:
image = ImageChops.blend(source_image, image, strength)
Expand Down

0 comments on commit 50d6dbb

Please sign in to comment.