farwew commited on
Commit
273e24a
·
verified ·
1 Parent(s): 4bfcd16

Upload 3 files

Browse files
Files changed (3) hide show
  1. CNN_Prak4_ML.h5 +3 -0
  2. app.py +63 -0
  3. requirement.txt +3 -0
CNN_Prak4_ML.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fd8b10e96ef8fa2e2d16c3251e2b21d6d9ea0942dcaea4941ee632dcce219f4c
3
+ size 1781096
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import tensorflow as tf
3
+ from tensorflow.keras.preprocessing.image import load_img, img_to_array
4
+ import numpy as np
5
+ from PIL import Image
6
+ import io
7
+
8
+ st.set_page_config(
9
+ page_title="Waste Classifier",
10
+ layout="centered"
11
+ )
12
+
13
+ @st.cache_resource
14
+ def load_model():
15
+ return tf.keras.models.load_model('CNN_Prak4_ML.h5')
16
+
17
+ def preprocess_image(img):
18
+ img = img.resize((244, 244))
19
+ img = img_to_array(img)
20
+ img = np.expand_dims(img, axis=0)
21
+ img = img / 255.0
22
+ return img
23
+
24
+ LABEL_CLASS = {
25
+ 0: "Cardboard",
26
+ 1: "Glass",
27
+ 2: "Metal",
28
+ 3: "Paper",
29
+ 4: "Textile Trash",
30
+ 5: "Vegetation"
31
+ }
32
+
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
+
40
+ if uploaded_file is not None:
41
+ image = Image.open(uploaded_file)
42
+ st.image(image, caption='Uploaded Image', use_column_width=True)
43
+
44
+ if st.button('Predict'):
45
+ model = load_model()
46
+
47
+ processed_image = preprocess_image(image)
48
+
49
+ with st.spinner('Predicting...'):
50
+ prediction = model.predict(processed_image)
51
+ pred_class = LABEL_CLASS[np.argmax(prediction)]
52
+ confidence = float(prediction.max()) * 100
53
+
54
+ st.success(f'Prediction: {pred_class.upper()}')
55
+ st.info(f'Confidence: {confidence:.2f}%')
56
+
57
+ st.write("Class Probabilities:")
58
+ for i, prob in enumerate(prediction[0]):
59
+ st.progress(float(prob))
60
+ st.write(f"{LABEL_CLASS[i]}: {float(prob)*100:.2f}%")
61
+
62
+ if __name__ == "__main__":
63
+ main()
requirement.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ pillow==10.4.0
2
+ streamlit==1.39.0
3
+ tensorflow==2.18.0