File size: 1,529 Bytes
5014798
8b3a8c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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"""<style>
        .stApp {{
            background-color: {color};
        }}
    </style>""", 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"""
        <style>
        .stApp {{
            background-image: url("data:image/png;base64,{encoded}");
            background-size: cover;
        }}
        </style>
    """, 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("<h1 style='text-align:center;'>πŸ₯¦ Vegetable Image Classifier πŸ₯•</h1>", unsafe_allow_html=True)