import gradio as gr import cv2 import numpy as np def process_images(files, blending_weight=0.5): # Process the uploaded image files here # You can access the uploaded files in the 'files' parameter as a list # For example, you can loop through the files and perform operations on them images = [np.array(img) for img in files] # Ensure all images have the same data type (CV_8U) for i in range(len(images)): # Ensure the image is a NumPy array and has the desired data type if images is not None: images = images.astype(np.uint8) else: # Handle the case where the image couldn't be loaded print("Failed to load the image") # Perform the image operation (e.g., blending) result_image = images[0].copy() for img in images[1:]: result_image = cv2.addWeighted(result_image, 1 - blending_weight, img, blending_weight, 0) # Convert the result image to PIL format for Gradio display result_pil_image = cv2.cvtColor(result_image, cv2.COLOR_BGR2RGB) return result_pil_image iface = gr.Interface( fn=process_images, inputs=gr.inputs.File(type="file", label="multiple files", file_count='multiple'), outputs=gr.outputs.Image(type="pil", label="Blended Image") ) iface.launch()