import streamlit as st from tensorflow.keras.models import load_model from PIL import Image import numpy as np # Load the pre-trained model model = load_model('cnn_model.h5') # Define a function to process the uploaded image def process_image(img): img = img.resize((64, 64)) # Resize the image to match the model input img = np.array(img) # Convert the image to a numpy array img = img / 255.0 # Normalize the image img = np.expand_dims(img, axis=0) # Add an extra dimension for batch size return img # Set page config for a better title and centered layout st.set_page_config(page_title="Flower Recognition", page_icon="🌸", layout="centered") # Title with emoji st.title('🌸 Flower Recognition 🌸') # File uploader widget with a centered label file = st.file_uploader("Choose a flower image", type=['jpg', 'jpeg', 'png']) # Display uploaded image if file is chosen if file is not None: img = Image.open(file) # Display uploaded image with center alignment st.image(img, caption='Uploaded Image') # Process the image and make predictions image = process_image(img) predictions = model.predict(image) predicted_class = np.argmax(predictions) # Class names class_names = ['Daisy', 'Dandelion', 'Rose', 'Sunflower', 'Tupil'] # Show prediction in a visually appealing way with centered text st.markdown(f"### 🌼 **Prediction**: 🌼") st.markdown(f"#### The model predicts this flower as: **{class_names[predicted_class]}**") # Add a stylish container to make the output look cleaner st.markdown(""" """, unsafe_allow_html=True) # Center all elements and create a more modern design st.markdown(""" """, unsafe_allow_html=True) # Optional footer or additional message st.markdown(""" """, unsafe_allow_html=True)