Update app.py
Browse files
app.py
CHANGED
|
@@ -2,26 +2,26 @@ import cv2 as cv
|
|
| 2 |
import numpy as np
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
def
|
| 6 |
-
#
|
| 7 |
image = np.array(image)
|
| 8 |
-
#
|
| 9 |
image = cv.cvtColor(image, cv.COLOR_RGB2BGR)
|
| 10 |
-
#
|
| 11 |
gray_image = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
|
| 12 |
return gray_image
|
| 13 |
|
| 14 |
-
#
|
| 15 |
with gr.Blocks() as demo:
|
| 16 |
-
gr.Markdown("#
|
| 17 |
-
gr.Markdown("
|
| 18 |
|
| 19 |
image_input = gr.Image(type='pil')
|
| 20 |
-
image_output = gr.Image(type="numpy", label="
|
| 21 |
|
| 22 |
-
#
|
| 23 |
-
|
| 24 |
-
|
| 25 |
|
| 26 |
if __name__ == "__main__":
|
| 27 |
demo.launch()
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
+
def nostalgic_effect(image):
|
| 6 |
+
# Convert the image to a NumPy array
|
| 7 |
image = np.array(image)
|
| 8 |
+
# Convert from RGB to BGR (Gradio inputs in RGB, OpenCV works in BGR)
|
| 9 |
image = cv.cvtColor(image, cv.COLOR_RGB2BGR)
|
| 10 |
+
# Convert to grayscale
|
| 11 |
gray_image = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
|
| 12 |
return gray_image
|
| 13 |
|
| 14 |
+
# Creating the Gradio interface
|
| 15 |
with gr.Blocks() as demo:
|
| 16 |
+
gr.Markdown("# Convert Image to Black and White!")
|
| 17 |
+
gr.Markdown("Upload an image and see it transformed to black and white...")
|
| 18 |
|
| 19 |
image_input = gr.Image(type='pil')
|
| 20 |
+
image_output = gr.Image(type="numpy", label="Converted Image")
|
| 21 |
|
| 22 |
+
# Connecting the function to Gradio components:
|
| 23 |
+
convert_btn = gr.Button("Convert")
|
| 24 |
+
convert_btn.click(fn=nostalgic_effect, inputs=image_input, outputs=image_output)
|
| 25 |
|
| 26 |
if __name__ == "__main__":
|
| 27 |
demo.launch()
|