Grayscale / app.py
HErsoy's picture
Update app.py
02a9c8c verified
raw
history blame contribute delete
913 Bytes
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()