Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +1 -66
- requirement.txt +0 -5
app.py
CHANGED
@@ -1,67 +1,3 @@
|
|
1 |
-
<<<<<<< HEAD
|
2 |
-
import streamlit as st
|
3 |
-
import tensorflow as tf
|
4 |
-
from tensorflow.keras.preprocessing.image import load_img, img_to_array
|
5 |
-
import numpy as np
|
6 |
-
from PIL import Image
|
7 |
-
import io
|
8 |
-
|
9 |
-
st.set_page_config(
|
10 |
-
page_title="Waste Classifier",
|
11 |
-
layout="centered"
|
12 |
-
)
|
13 |
-
|
14 |
-
@st.cache_resource
|
15 |
-
def load_model():
|
16 |
-
return tf.keras.models.load_model('CNN_Prak4_ML.h5')
|
17 |
-
|
18 |
-
def preprocess_image(img):
|
19 |
-
img = img.resize((244, 244))
|
20 |
-
img = img_to_array(img)
|
21 |
-
img = np.expand_dims(img, axis=0)
|
22 |
-
img = img / 255.0
|
23 |
-
return img
|
24 |
-
|
25 |
-
LABEL_CLASS = {
|
26 |
-
0: "Cardboard",
|
27 |
-
1: "Glass",
|
28 |
-
2: "Metal",
|
29 |
-
3: "Paper",
|
30 |
-
4: "Textile Trash",
|
31 |
-
5: "Vegetation"
|
32 |
-
}
|
33 |
-
|
34 |
-
|
35 |
-
def main():
|
36 |
-
st.title("Waste Classifier")
|
37 |
-
st.write("Upload an image and the model will predict whether it's a chihuahua or a muffin!")
|
38 |
-
|
39 |
-
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
40 |
-
|
41 |
-
if uploaded_file is not None:
|
42 |
-
image = Image.open(uploaded_file)
|
43 |
-
st.image(image, caption='Uploaded Image', use_column_width=True)
|
44 |
-
|
45 |
-
if st.button('Predict'):
|
46 |
-
model = load_model()
|
47 |
-
|
48 |
-
processed_image = preprocess_image(image)
|
49 |
-
|
50 |
-
with st.spinner('Predicting...'):
|
51 |
-
prediction = model.predict(processed_image)
|
52 |
-
pred_class = LABEL_CLASS[np.argmax(prediction)]
|
53 |
-
confidence = float(prediction.max()) * 100
|
54 |
-
|
55 |
-
st.success(f'Prediction: {pred_class.upper()}')
|
56 |
-
st.info(f'Confidence: {confidence:.2f}%')
|
57 |
-
|
58 |
-
st.write("Class Probabilities:")
|
59 |
-
for i, prob in enumerate(prediction[0]):
|
60 |
-
st.progress(float(prob))
|
61 |
-
st.write(f"{LABEL_CLASS[i]}: {float(prob)*100:.2f}%")
|
62 |
-
|
63 |
-
if __name__ == "__main__":
|
64 |
-
=======
|
65 |
import streamlit as st
|
66 |
import tensorflow as tf
|
67 |
from tensorflow.keras.preprocessing.image import load_img, img_to_array
|
@@ -97,7 +33,7 @@ LABEL_CLASS = {
|
|
97 |
|
98 |
def main():
|
99 |
st.title("Waste Classifier")
|
100 |
-
st.write("Upload an image and the model will predict
|
101 |
|
102 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
103 |
|
@@ -124,5 +60,4 @@ def main():
|
|
124 |
st.write(f"{LABEL_CLASS[i]}: {float(prob)*100:.2f}%")
|
125 |
|
126 |
if __name__ == "__main__":
|
127 |
-
>>>>>>> 9014ce89a3d5b013b1a3e93a65c21b8e932a0117
|
128 |
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import tensorflow as tf
|
3 |
from tensorflow.keras.preprocessing.image import load_img, img_to_array
|
|
|
33 |
|
34 |
def main():
|
35 |
st.title("Waste Classifier")
|
36 |
+
st.write("Upload an image and the model will predict waste image")
|
37 |
|
38 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
39 |
|
|
|
60 |
st.write(f"{LABEL_CLASS[i]}: {float(prob)*100:.2f}%")
|
61 |
|
62 |
if __name__ == "__main__":
|
|
|
63 |
main()
|
requirement.txt
CHANGED
@@ -1,8 +1,3 @@
|
|
1 |
-
<<<<<<< HEAD
|
2 |
pillow==10.4.0
|
3 |
streamlit==1.39.0
|
4 |
-
=======
|
5 |
-
pillow==10.4.0
|
6 |
-
streamlit==1.39.0
|
7 |
-
>>>>>>> 9014ce89a3d5b013b1a3e93a65c21b8e932a0117
|
8 |
tensorflow==2.18.0
|
|
|
|
|
1 |
pillow==10.4.0
|
2 |
streamlit==1.39.0
|
|
|
|
|
|
|
|
|
3 |
tensorflow==2.18.0
|