streamlit_UI / app.py
rumaisa1054's picture
Update app.py
14f21f2 verified
raw
history blame contribute delete
736 Bytes
import streamlit as st
import cv2
import numpy as np
from PIL import Image
st.title("🎨 Grayscale Image Converter")
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
if uploaded_file is not None:
image = Image.open(uploaded_file)
# Convert PIL to OpenCV format
img_array = np.array(image)
if img_array.shape[2] == 4:
img_array = cv2.cvtColor(img_array, cv2.COLOR_RGBA2RGB)
gray_image = cv2.cvtColor(img_array, cv2.COLOR_RGB2GRAY)
# Display side-by-side in smaller size
col1, col2 = st.columns(2)
with col1:
st.image(image, caption="Original", width=250)
with col2:
st.image(gray_image, caption="Grayscale", width=250, channels="GRAY")