Spaces:
Configuration error
Configuration error
Update app.py
Browse files55 unmodified lines5657585960616238 unmodified lines10110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515655 unmodified lines
@spaces.GPU"""def fill_image(image, model_selection):
margin = 25638 unmodified lines cnet_image.paste(image, (0, 0), mask)
yield background, cnet_image"""
def fill_image(image, model_selection): source = image target_ratio=(9, 16) overlap=24 # Calculate the target width based on the 9:16 ratio target_width = (source.height * target_ratio[0]) // target_ratio[1] # Calculate margins margin_x = max(0, (target_width - source.width) // 2) margin_y = 0 # No vertical expansion # Calculate new output size output_size = (source.width + 2*margin_x, source.height + 2*margin_y) # Create a white background background = Image.new('RGB', output_size, (255, 255, 255)) # Calculate position to paste the original image position = (margin_x, margin_y) # Paste the original image onto the white background background.paste(source, position) # Create the mask mask = Image.new('L', output_size, 255) # Start with all white mask_draw = ImageDraw.Draw(mask) mask_draw.rectangle([ (position[0] + overlap, position[1] + overlap), (position[0] + source.width - overlap, position[1] + source.height - overlap) ], fill=0) # Prepare the image for ControlNet cnet_image = background.copy() cnet_image.paste(0, (0, 0), mask)
for image in pipe( prompt_embeds=prompt_embeds, negative_prompt_embeds=negative_prompt_embeds, pooled_prompt_embeds=pooled_prompt_embeds, negative_pooled_prompt_embeds=negative_pooled_prompt_embeds, image=cnet_image, ): yield image, cnet_image
image = image.convert("RGBA") cnet_image.paste(image, (0, 0), mask)
yield background, cnet_image
def clear_result(): return gr.update(value=None)app.py+50