Spaces:
Runtime error
Runtime error
Update app.py
Browse files8 unmodified lines9101112131440 unmodified lines555657585960616263646566675 unmodified lines7374757677787980818 unmodified linesfrom controlnet_union import ControlNetModel_Unionfrom pipeline_fill_sd_xl import StableDiffusionXLFillPipelineMODELS = {"RealVisXL V5.0 Lightning": "SG161222/RealVisXL_V5.0_Lightning",}40 unmodified lines@spaces.GPUdef fill_image(image, model_selection):source = image["background"]mask = image["layers"][0]alpha_channel = mask.split()[3]binary_mask = alpha_channel.point(lambda p: p > 0 and 255)cnet_image = source.copy()cnet_image.paste(0, (0, 0), binary_mask)for image in pipe(prompt_embeds=prompt_embeds,5 unmodified linesyield image, cnet_imageimage = image.convert("RGBA")cnet_image.paste(image, (0, 0), binary_mask)yield source, cnet_imagedef clear_result():8 unmodified lines91011121314151640 unmodified lines575859606162636465666768697071727374757677787980818283848586875 unmodified lines939495969798991001018 unmodified linesfrom controlnet_union import ControlNetModel_Unionfrom pipeline_fill_sd_xl import StableDiffusionXLFillPipelinefrom PIL import Image, ImageDrawMODELS = {"RealVisXL V5.0 Lightning": "SG161222/RealVisXL_V5.0_Lightning",}40 unmodified lines@spaces.GPUdef fill_image(image, model_selection):margin = 100# Open the original imagesource = image["image"] # Changed from image["background"] to match new input format# Calculate new output sizeoutput_size = (source.width + 2*margin, source.height + 2*margin)# Create a white backgroundbackground = Image.new('RGB', output_size, (255, 255, 255))# Calculate position to paste the original imageposition = (margin, margin)# 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, (position[0] + source.width, position[1] + source.height)], 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,5 unmodified linesyield image, cnet_imageimage = image.convert("RGBA")cnet_image.paste(image, (0, 0), mask)yield background, cnet_imagedef clear_result():
app.py+28-8