Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import cv2 | |
| import numpy as np | |
| # Define a function that performs the image operation with adjustable blending weight | |
| def perform_image_operation(images, blending_weight=0.5): | |
| # Convert the Gradio input images to NumPy arrays | |
| images = [np.array(img) for img in images] | |
| # 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 | |
| # Define the Gradio interface with multiple file uploads and an adjustable blending weight slider | |
| iface = gr.Interface( | |
| fn=perform_image_operation, | |
| inputs=[ | |
| gr.File(type="image", label="Image 1", multiple=True), | |
| gr.File(type="image", label="Image 2", multiple=True), | |
| gr.File(type="image", label="Image 3", multiple=True), | |
| gr.File(type="image", label="Image 4", multiple=True), | |
| gr.File(type="image", label="Image 5", multiple=True), | |
| gr.File(type="image", label="Image 6", multiple=True), | |
| gr.File(type="image", label="Image 7", multiple=True), | |
| gr.File(type="image", label="Image 8", multiple=True), | |
| gr.Slider(minimum=0, maximum=1, default=0.5, label="Blending Weight"), | |
| ], | |
| outputs=gr.outputs.Image(type="pil", label="Blended Image") | |
| ) | |
| # Start the Gradio app | |
| iface.launch() | |