import streamlit as st from tensorflow.keras.models import load_model from PIL import Image import numpy as np # Load the model model = load_model('cnn_model.h5', compile=False) # Function to process the uploaded image def process_image(img): img = img.resize((64, 64)) img = np.array(img) img = img / 255.0 img = np.expand_dims(img, axis=0) return img # Custom CSS for better design st.markdown(""" """, unsafe_allow_html=True) # Title of the application st.title('Glass Detection from Image 📸') # Brief description st.markdown('

Upload a photo, and the model will predict whether there is a glass or not.

', unsafe_allow_html=True) # File uploader for the user to upload an image file = st.file_uploader('Select an image (jpg, jpeg, png)', type=['jpg', 'jpeg', 'png']) if file is not None: # Displaying the uploaded image img = Image.open(file) st.image(img, caption='Uploaded Image') # Processing the image image = process_image(img) prediction = model.predict(image) # Get the predicted class index predicted_class = np.argmax(prediction, axis=-1) # Displaying prediction result st.subheader("Prediction Result:") if predicted_class == 1: prediction_text = '✅ There is a glass' else: prediction_text = '❌ There is no a glass' st.write(prediction_text) else: st.write("Please upload an image to get started.") # Footer st.markdown("

Built with 💚 by Senasu Demir

", unsafe_allow_html=True)