import streamlit as st import tensorflow as tf from PIL import Image import numpy as np import base64 from tensorflow.keras.models import load_model as keras_load_model # Set Streamlit page config st.set_page_config(page_title="Vegetable Classifier", page_icon="🥦", layout="centered") # Optional: Set background color def set_bg_color(color="#f0fff0"): st.markdown(f"""""", unsafe_allow_html=True) # Optional: Background image def add_bg_image(image_file): with open(image_file, "rb") as f: encoded = base64.b64encode(f.read()).decode() st.markdown(f""" """, unsafe_allow_html=True) # Class labels class_names = [ 'Bean', 'Bitter_Gourd', 'Bottle_Gourd', 'Brinjal', 'Broccoli', 'Cabbage', 'Capsicum', 'Carrot', 'Cauliflower', 'Cucumber', 'Papaya', 'Potato', 'Pumpkin', 'Radish', 'Tomato' ] # Load model safely @st.cache_resource def load_model_safe(): try: model = load_model("vegetable_cnn_improved (2).h5", compile=False) return model except Exception as e: st.error(f"❌ Error loading model: {e}") return None # Load the model model = load_model_safe() # UI set_bg_color() st.markdown("

🥦 Vegetable Image Classifier 🥕

", unsafe_allow_html=True)