File size: 1,533 Bytes
b2c34f9
6075a4e
 
db00f9d
83fd970
ee05941
83fd970
ee05941
83fd970
8e6237a
83fd970
 
 
db00f9d
8e6237a
83fd970
8e6237a
b2c34f9
ee05941
b2c34f9
8e6237a
b2c34f9
ee05941
 
 
 
 
 
 
 
 
b2c34f9
8e6237a
b2c34f9
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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()