Sridhar027 commited on
Commit
8b3a8c8
·
verified ·
1 Parent(s): d5232f5

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +53 -39
src/streamlit_app.py CHANGED
@@ -1,40 +1,54 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
5
-
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import tensorflow as tf
3
+ from PIL import Image
4
+ import numpy as np
5
+ import base64
6
+ from tensorflow.keras.models import load_model as keras_load_model
7
+
8
+ # Set Streamlit page config
9
+ st.set_page_config(page_title="Vegetable Classifier", page_icon="🥦", layout="centered")
10
+
11
+ # Optional: Set background color
12
+ def set_bg_color(color="#f0fff0"):
13
+ st.markdown(f"""<style>
14
+ .stApp {{
15
+ background-color: {color};
16
+ }}
17
+ </style>""", unsafe_allow_html=True)
18
+
19
+ # Optional: Background image
20
+ def add_bg_image(image_file):
21
+ with open(image_file, "rb") as f:
22
+ encoded = base64.b64encode(f.read()).decode()
23
+ st.markdown(f"""
24
+ <style>
25
+ .stApp {{
26
+ background-image: url("data:image/png;base64,{encoded}");
27
+ background-size: cover;
28
+ }}
29
+ </style>
30
+ """, unsafe_allow_html=True)
31
+
32
+ # Class labels
33
+ class_names = [
34
+ 'Bean', 'Bitter_Gourd', 'Bottle_Gourd', 'Brinjal', 'Broccoli',
35
+ 'Cabbage', 'Capsicum', 'Carrot', 'Cauliflower', 'Cucumber',
36
+ 'Papaya', 'Potato', 'Pumpkin', 'Radish', 'Tomato'
37
+ ]
38
+
39
+ # Load model safely
40
+ @st.cache_resource
41
+ def load_model_safe():
42
+ try:
43
+ model = load_model("vegetable_cnn_improved (2).h5", compile=False)
44
+ return model
45
+ except Exception as e:
46
+ st.error(f"❌ Error loading model: {e}")
47
+ return None
48
+
49
+ # Load the model
50
+ model = load_model_safe()
51
+
52
+ # UI
53
+ set_bg_color()
54
+ st.markdown("<h1 style='text-align:center;'>🥦 Vegetable Image Classifier 🥕</h1>", unsafe_allow_html=True)