import gradio as gr from PIL import Image import cv2 def merge_images(image1, image2, method="concatenate"): """ Merges two images using the specified method. Args: image1 (PIL.Image): The first image. image2 (PIL.Image): The second image. method (str, optional): The method for merging. Defaults to "concatenate". Supported methods: - "concatenate": Concatenates the images horizontally. - "average": Creates an average blend of the two images. - "custom": Allows for custom logic using (image1, image2) as input. Returns: PIL.Image: The merged image. """ img1 = cv2.resize(image1, (512,512)) img2 = cv2.resize(image2, (512,512)) img = img1*0.5 + img2*0.5 img = img.astype('uint8') return img # Define Gradio interface interface = gr.Interface( fn=merge_images, inputs=[gr.Image(label="Image 1", type="pil"), gr.Image(label="Image 2", type="pil")], outputs="image", # Allow selection of merge method with a dropdown elem_id="merge-method", elem_attrs={"merge-method": {"type": "dropdown", "choices": ["concatenate", "average", "custom"]}}, title="Image Merger", description="Merge two uploaded images using the selected method." ) interface.launch()