forked from ironhack-labs/project-4-cv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
37 lines (29 loc) · 1.35 KB
/
app.py
File metadata and controls
37 lines (29 loc) · 1.35 KB
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
import streamlit as st
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.image import load_img, img_to_array
import numpy as np
# Load the trained model
MODEL_PATH = "best_mobilenet_model.keras"
model = load_model(MODEL_PATH)
# Define class labels
class_labels = {0: "Household Waste", 1: "Recyclable"}
# Streamlit interface
st.title("Recycling Classification App")
st.write("Upload an image, and the model will classify it as either 'Recyclable' or 'Household Waste'.")
# File uploader
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
if uploaded_file is not None:
# Display uploaded image
st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
st.write("Classifying...")
# Preprocess the image
img = load_img(uploaded_file, target_size=(224, 224))
img_array = img_to_array(img) / 255.0 # Normalize to [0, 1]
img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
# Make prediction
prediction = model.predict(img_array)
predicted_class = 1 if prediction > 0.5 else 0
confidence = prediction[0][0] if predicted_class == 1 else 1 - prediction[0][0]
# Display result
st.write(f"Prediction: **{class_labels[predicted_class]}**")
st.write(f"Confidence: **{confidence:.2f}**")