Spaces:
Runtime error
Runtime error
Update app.py
Browse files101 unmodified lines10210310410510610710853 unmodified lines162163164165166167101 unmodified linescnet_image.paste(image, (0, 0), mask)yield background, cnet_image"""@spaces.GPUdef fill_image(image, model_selection):53 unmodified linescnet_image.paste(image, (0, 0), mask)yield background, cnet_imagedef clear_result():return gr.update(value=None)101 unmodified lines10210310410510610710853 unmodified lines162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228101 unmodified linescnet_image.paste(image, (0, 0), mask)yield background, cnet_image@spaces.GPUdef fill_image(image, model_selection):53 unmodified linescnet_image.paste(image, (0, 0), mask)yield background, cnet_image"""def fill_image(image, model_selection):source = imagetarget_ratio = (16, 9) # Set the new target ratio to 16:9target_width = 1280 # Adjust target width based on desired resolutionoverlap = 48fade_width = 24max_height = 720 # Adjust max height instead of width# Resize the image if it's taller than max_heightif source.height > max_height:scale_factor = max_height / source.heightnew_height = max_heightnew_width = int(source.width * scale_factor)source = source.resize((new_width, new_height), Image.LANCZOS)# Calculate the required width for the 16:9 ratiotarget_width = (source.height * target_ratio[0]) // target_ratio[1]# Calculate margins (now left and right)margin_x = (target_width - source.width) // 2# Calculate new output sizeoutput_size = (target_width, source.height)# Create a white backgroundbackground = Image.new('RGB', output_size, (255, 255, 255))# Calculate position to paste the original imageposition = (margin_x, 0)# 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([(margin_x + overlap, overlap),(margin_x + source.width - overlap, 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+62-1