| 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 |
|
|
| |
| st.set_page_config(page_title="Vegetable Classifier", page_icon="🥦", layout="centered") |
|
|
| |
| def set_bg_color(color="#f0fff0"): |
| st.markdown(f"""<style> |
| .stApp {{ |
| background-color: {color}; |
| }} |
| </style>""", unsafe_allow_html=True) |
|
|
| |
| def add_bg_image(image_file): |
| with open(image_file, "rb") as f: |
| encoded = base64.b64encode(f.read()).decode() |
| st.markdown(f""" |
| <style> |
| .stApp {{ |
| background-image: url("data:image/png;base64,{encoded}"); |
| background-size: cover; |
| }} |
| </style> |
| """, unsafe_allow_html=True) |
|
|
| |
| class_names = [ |
| 'Bean', 'Bitter_Gourd', 'Bottle_Gourd', 'Brinjal', 'Broccoli', |
| 'Cabbage', 'Capsicum', 'Carrot', 'Cauliflower', 'Cucumber', |
| 'Papaya', 'Potato', 'Pumpkin', 'Radish', 'Tomato' |
| ] |
|
|
| |
| @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 |
|
|
| |
| model = load_model_safe() |
|
|
| |
| set_bg_color() |
| st.markdown("<h1 style='text-align:center;'>🥦 Vegetable Image Classifier 🥕</h1>", unsafe_allow_html=True) |