Spaces:
Sleeping
Sleeping
File size: 1,778 Bytes
13cb3ce 8f75876 302f20e 13cb3ce 8f75876 13cb3ce 7489eab 1cd414e 13cb3ce 1cd414e 302f20e 1cd414e 13cb3ce 1cd414e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
import logging
from typing import List
import torch
import numpy as np
from PIL import Image
from helpers import flush, postprocess_image_masking, convolution
from pipelines import get_inpainting_pipeline
LOGGING = logging.getLogger(__name__)
@torch.inference_mode()
def make_inpainting(positive_prompt: str,
image: Image,
mask_image: np.ndarray,
negative_prompt: str,
num_of_images: int,
resolution:int ) -> List[Image.Image]:
print("make_inpainting", positive_prompt, image, mask_image, negative_prompt, num_of_images, resolution)
"""Method to make inpainting
Args:
positive_prompt (str): positive prompt string
image (Image): input image
mask_image (np.ndarray): mask image
negative_prompt (str, optional): negative prompt string. Defaults to "".
Returns:
List[Image.Image]: list of generated images
"""
pipe = get_inpainting_pipeline()
mask_image = Image.fromarray((mask_image * 255).astype(np.uint8))
mask_image_postproc = convolution(mask_image)
flush()
retList=[]
for x in range(num_of_images):
resp = pipe(image=image,
mask_image=mask_image,
prompt=positive_prompt,
negative_prompt=negative_prompt,
num_inference_steps=50,
height=resolution,
width=resolution,
)
print("RESP !!!!",resp)
generated_image = resp.images[0]
generated_image = postprocess_image_masking(generated_image, image, mask_image_postproc)
retList.append(generated_image)
return retList
|