Spaces:
Sleeping
Sleeping
Update app.py
Browse files1 unmodified line23456789101112131415161718192021222324254 unmodified lines303132331 unmodified lineimport gradio as grimport numpy as np# Function to overlay image1 onto the background of image2def overlay_images(image1, image2):# Convert NumPy arrays to PIL imagesimg1 = Image.fromarray(image1)img2 = Image.fromarray(image2)# Resize image1 to fit image2 if necessaryimg1 = img1.resize(img2.size)# Create a new image by blending image1 onto the background of image2combined = Image.new("RGBA", img2.size)combined = Image.alpha_composite(combined, img2.convert("RGBA"))combined = Image.alpha_composite(combined, img1.convert("RGBA"))return combined# Gradio interface for Hugging Face Spaceiface = gr.Interface(fn=overlay_images,inputs=[gr.inputs.Image(type="numpy", label="Upload Image 1 (Foreground)"),4 unmodified linesdescription="Upload two images. The first image will be placed onto the background of the second image.")iface.launch()1 unmodified line23456789101112131415161718192021224 unmodified lines272829301 unmodified lineimport gradio as grimport numpy as npdef overlay_images(image1, image2):img1 = Image.fromarray(image1)img2 = Image.fromarray(image2)img1 = img1.resize(img2.size)combined = Image.new("RGBA", img2.size)combined = Image.alpha_composite(combined, img2.convert("RGBA"))combined = Image.alpha_composite(combined, img1.convert("RGBA"))return combinedimg2img = gr.Interface(fn=overlay_images,inputs=[gr.inputs.Image(type="numpy", label="Upload Image 1 (Foreground)"),4 unmodified linesdescription="Upload two images. The first image will be placed onto the background of the second image.")img2img.launch()
app.py+4-7