Spaces:
Configuration error
Configuration error
Update app.py
Browse files55 unmodified lines56575859606138 unmodified lines10010110210310410510655 unmodified lines@spaces.GPUdef fill_image(image, model_selection):margin = 25638 unmodified linescnet_image.paste(image, (0, 0), mask)yield background, cnet_imagedef clear_result():return gr.update(value=None)55 unmodified lines5657585960616238 unmodified lines10110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515655 unmodified lines@spaces.GPU"""def fill_image(image, model_selection):margin = 25638 unmodified linescnet_image.paste(image, (0, 0), mask)yield background, cnet_image"""def fill_image(image, model_selection):source = imagetarget_ratio=(9, 16)overlap=24# Calculate the target width based on the 9:16 ratiotarget_width = (source.height * target_ratio[0]) // target_ratio[1]# Calculate marginsmargin_x = max(0, (target_width - source.width) // 2)margin_y = 0 # No vertical expansion# Calculate new output sizeoutput_size = (source.width + 2*margin_x, source.height + 2*margin_y)# Create a white backgroundbackground = Image.new('RGB', output_size, (255, 255, 255))# Calculate position to paste the original imageposition = (margin_x, margin_y)# Paste the original image onto the white backgroundbackground.paste(source, position)# Create the maskmask = Image.new('L', output_size, 255) # Start with all whitemask_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 ControlNetcnet_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_imageimage = image.convert("RGBA")cnet_image.paste(image, (0, 0), mask)yield background, cnet_imagedef clear_result():return gr.update(value=None)
app.py+50