File size: 913 Bytes
fc2b39a 02a9c8c fc2b39a 02a9c8c fc2b39a 02a9c8c fc2b39a 02a9c8c fc2b39a 02a9c8c fc2b39a 02a9c8c fc2b39a 02a9c8c fc2b39a | 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 | import cv2 as cv
import numpy as np
import gradio as gr
def nostalgic_effect(image):
# Convert the image to a NumPy array
image = np.array(image)
# Convert from RGB to BGR (Gradio inputs in RGB, OpenCV works in BGR)
image = cv.cvtColor(image, cv.COLOR_RGB2BGR)
# Convert to grayscale
gray_image = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
return gray_image
# Creating the Gradio interface
with gr.Blocks() as demo:
gr.Markdown("# Convert Image to Black and White!")
gr.Markdown("Upload an image and see it transformed to black and white...")
image_input = gr.Image(type='pil')
image_output = gr.Image(type="numpy", label="Converted Image")
# Connecting the function to Gradio components:
convert_btn = gr.Button("Convert")
convert_btn.click(fn=nostalgic_effect, inputs=image_input, outputs=image_output)
if __name__ == "__main__":
demo.launch() |