divya55 commited on
Commit
685abe8
·
verified ·
1 Parent(s): 3fa355c

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +131 -131
src/streamlit_app.py CHANGED
@@ -1,131 +1,131 @@
1
- import streamlit as st
2
- import pickle
3
- import numpy as np
4
- from PIL import Image
5
- import matplotlib.pyplot as plt
6
-
7
- # -----------------------------
8
- # Load trained Image Classifier
9
- # -----------------------------
10
- with open("image_model.pkl", "rb") as f:
11
- model = pickle.load(f)
12
-
13
- # -----------------------------
14
- # Streamlit Page Config
15
- # -----------------------------
16
- st.set_page_config(page_title="Image Classification App", layout="wide")
17
-
18
- # Sidebar Navigation
19
- st.sidebar.title("Navigation")
20
- menu = [
21
- "Introduction",
22
- "Problem Statement",
23
- "Data Collection",
24
- "Insights",
25
- "Solution Development",
26
- "Try It Out"
27
- ]
28
- choice = st.sidebar.radio("Go to", menu)
29
-
30
- # -----------------------------
31
- # Page 1: Introduction
32
- # -----------------------------
33
- if choice == "Introduction":
34
- st.title("Image Classification Project")
35
- st.write("""
36
- In many industries today, large volumes of images are generated every day.
37
- Manually checking and sorting them is **time-consuming and error-prone**.
38
-
39
- I built this project to explore how **automation can speed up image-based tasks**,
40
- reduce dependency on human effort, and improve decision-making.
41
- """)
42
-
43
- # -----------------------------
44
- # Page 2: Problem Statement
45
- # -----------------------------
46
- elif choice == "Problem Statement":
47
- st.title("Problem Statement")
48
- st.write("""
49
- Organisations face challenges like:
50
-
51
- - Handling **huge sets of unlabelled images**
52
- - **Human errors** during manual classification
53
- - **Delays in decision-making** due to slow processing
54
-
55
- A system that can **instantly classify images into the correct categories**
56
- can save time, improve accuracy, and reduce operational costs.
57
- """)
58
-
59
- # -----------------------------
60
- # Page 3: Data Collection
61
- # -----------------------------
62
- elif choice == "Data Collection":
63
- st.title("Data Collection")
64
- st.write("""
65
- - Collected images from multiple categories (labelled data)
66
- - Ensured a **balanced set of examples** from each category
67
- - Standardised image size and format for consistency
68
- - Split into **training and testing sets** to build and evaluate the system
69
-
70
- This helped create a reliable base for the system to learn from.
71
- """)
72
-
73
- # -----------------------------
74
- # Page 4: Insights
75
- # -----------------------------
76
- elif choice == "Insights":
77
- st.title("Key Insights from Data")
78
- st.write("""
79
- During initial exploration of the dataset:
80
-
81
- - Found clear **visual differences between categories**
82
- - Verified **balanced distribution** of images across classes
83
- - Confirmed **image sizes and quality were consistent**
84
-
85
- These insights gave confidence that the data was suitable for automation.
86
- """)
87
-
88
- st.subheader("Example Images (Randomised)")
89
- fig, ax = plt.subplots(1, 3, figsize=(9, 3))
90
- for i in range(3):
91
- ax[i].imshow(np.random.rand(64, 64, 3))
92
- ax[i].set_title(f"Class {i}")
93
- ax[i].axis("off")
94
- st.pyplot(fig)
95
-
96
- # -----------------------------
97
- # Page 5: Solution Development
98
- # -----------------------------
99
- elif choice == "Solution Development":
100
- st.title("Solution Development")
101
- st.write("""
102
- We designed and trained an image classification system that can:
103
-
104
- - Analyse image patterns
105
- - Learn differences between categories
106
- - Predict the category of unseen images
107
-
108
- The system was tested on new data to validate its performance
109
- before making it available as a user-friendly web app.
110
- """)
111
-
112
- # -----------------------------
113
- # Page 6: Try It Out
114
- # -----------------------------
115
- elif choice == "Try It Out":
116
- st.title("Try the Classifier")
117
- st.write("Upload an image below to see how the system classifies it:")
118
-
119
- uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
120
-
121
- if uploaded_file is not None:
122
- image = Image.open(uploaded_file).convert("RGB")
123
- st.image(image, caption="Uploaded Image", use_column_width=True)
124
-
125
- # Preprocess image (resize -> flatten -> scale handled by the trained pipeline)
126
- img_resized = image.resize((64, 64))
127
- img_array = np.array(img_resized).flatten().reshape(1, -1)
128
-
129
- # Predict
130
- prediction = model.predict(img_array)[0]
131
- st.success(f"Predicted Category: **{prediction}**")
 
1
+ import streamlit as st
2
+ import pickle
3
+ import numpy as np
4
+ from PIL import Image
5
+ import matplotlib.pyplot as plt
6
+
7
+ # -----------------------------
8
+ # Load trained Image Classifier
9
+ # -----------------------------
10
+ with open("/app/src/image_model.pkl", "rb") as f:
11
+ model = pickle.load(f)
12
+
13
+ # -----------------------------
14
+ # Streamlit Page Config
15
+ # -----------------------------
16
+ st.set_page_config(page_title="Image Classification App", layout="wide")
17
+
18
+ # Sidebar Navigation
19
+ st.sidebar.title("Navigation")
20
+ menu = [
21
+ "Introduction",
22
+ "Problem Statement",
23
+ "Data Collection",
24
+ "Insights",
25
+ "Solution Development",
26
+ "Try It Out"
27
+ ]
28
+ choice = st.sidebar.radio("Go to", menu)
29
+
30
+ # -----------------------------
31
+ # Page 1: Introduction
32
+ # -----------------------------
33
+ if choice == "Introduction":
34
+ st.title("Image Classification Project")
35
+ st.write("""
36
+ In many industries today, large volumes of images are generated every day.
37
+ Manually checking and sorting them is **time-consuming and error-prone**.
38
+
39
+ I built this project to explore how **automation can speed up image-based tasks**,
40
+ reduce dependency on human effort, and improve decision-making.
41
+ """)
42
+
43
+ # -----------------------------
44
+ # Page 2: Problem Statement
45
+ # -----------------------------
46
+ elif choice == "Problem Statement":
47
+ st.title("Problem Statement")
48
+ st.write("""
49
+ Organisations face challenges like:
50
+
51
+ - Handling **huge sets of unlabelled images**
52
+ - **Human errors** during manual classification
53
+ - **Delays in decision-making** due to slow processing
54
+
55
+ A system that can **instantly classify images into the correct categories**
56
+ can save time, improve accuracy, and reduce operational costs.
57
+ """)
58
+
59
+ # -----------------------------
60
+ # Page 3: Data Collection
61
+ # -----------------------------
62
+ elif choice == "Data Collection":
63
+ st.title("Data Collection")
64
+ st.write("""
65
+ - Collected images from multiple categories (labelled data)
66
+ - Ensured a **balanced set of examples** from each category
67
+ - Standardised image size and format for consistency
68
+ - Split into **training and testing sets** to build and evaluate the system
69
+
70
+ This helped create a reliable base for the system to learn from.
71
+ """)
72
+
73
+ # -----------------------------
74
+ # Page 4: Insights
75
+ # -----------------------------
76
+ elif choice == "Insights":
77
+ st.title("Key Insights from Data")
78
+ st.write("""
79
+ During initial exploration of the dataset:
80
+
81
+ - Found clear **visual differences between categories**
82
+ - Verified **balanced distribution** of images across classes
83
+ - Confirmed **image sizes and quality were consistent**
84
+
85
+ These insights gave confidence that the data was suitable for automation.
86
+ """)
87
+
88
+ st.subheader("Example Images (Randomised)")
89
+ fig, ax = plt.subplots(1, 3, figsize=(9, 3))
90
+ for i in range(3):
91
+ ax[i].imshow(np.random.rand(64, 64, 3))
92
+ ax[i].set_title(f"Class {i}")
93
+ ax[i].axis("off")
94
+ st.pyplot(fig)
95
+
96
+ # -----------------------------
97
+ # Page 5: Solution Development
98
+ # -----------------------------
99
+ elif choice == "Solution Development":
100
+ st.title("Solution Development")
101
+ st.write("""
102
+ We designed and trained an image classification system that can:
103
+
104
+ - Analyse image patterns
105
+ - Learn differences between categories
106
+ - Predict the category of unseen images
107
+
108
+ The system was tested on new data to validate its performance
109
+ before making it available as a user-friendly web app.
110
+ """)
111
+
112
+ # -----------------------------
113
+ # Page 6: Try It Out
114
+ # -----------------------------
115
+ elif choice == "Try It Out":
116
+ st.title("Try the Classifier")
117
+ st.write("Upload an image below to see how the system classifies it:")
118
+
119
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
120
+
121
+ if uploaded_file is not None:
122
+ image = Image.open(uploaded_file).convert("RGB")
123
+ st.image(image, caption="Uploaded Image", use_column_width=True)
124
+
125
+ # Preprocess image (resize -> flatten -> scale handled by the trained pipeline)
126
+ img_resized = image.resize((64, 64))
127
+ img_array = np.array(img_resized).flatten().reshape(1, -1)
128
+
129
+ # Predict
130
+ prediction = model.predict(img_array)[0]
131
+ st.success(f"Predicted Category: **{prediction}**")