Spaces:
Build error
Build error
Upload 3 files
Browse filesFiles changed (3)
- CNN_Prak4_ML.h5Added+3
- app.pyAdded+128
- requirement.txtAdded+8
123version https://git-lfs.github.com/spec/v1oid sha256:fd8b10e96ef8fa2e2d16c3251e2b21d6d9ea0942dcaea4941ee632dcce219f4csize 1781096123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128<<<<<<< HEADimport streamlit as stimport tensorflow as tffrom tensorflow.keras.preprocessing.image import load_img, img_to_arrayimport numpy as npfrom PIL import Imageimport io
st.set_page_config( page_title="Waste Classifier", layout="centered")
@st.cache_resourcedef load_model(): return tf.keras.models.load_model('CNN_Prak4_ML.h5')
def preprocess_image(img): img = img.resize((244, 244)) img = img_to_array(img) img = np.expand_dims(img, axis=0) img = img / 255.0 return img
LABEL_CLASS = { 0: "Cardboard", 1: "Glass", 2: "Metal", 3: "Paper", 4: "Textile Trash", 5: "Vegetation"}
def main(): st.title("Waste Classifier") st.write("Upload an image and the model will predict whether it's a chihuahua or a muffin!") uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"]) if uploaded_file is not None: image = Image.open(uploaded_file) st.image(image, caption='Uploaded Image', use_column_width=True) if st.button('Predict'): model = load_model() processed_image = preprocess_image(image) with st.spinner('Predicting...'): prediction = model.predict(processed_image) pred_class = LABEL_CLASS[np.argmax(prediction)] confidence = float(prediction.max()) * 100 st.success(f'Prediction: {pred_class.upper()}') st.info(f'Confidence: {confidence:.2f}%') st.write("Class Probabilities:") for i, prob in enumerate(prediction[0]): st.progress(float(prob)) st.write(f"{LABEL_CLASS[i]}: {float(prob)*100:.2f}%")
if __name__ == "__main__":=======import streamlit as st
import tensorflow as tf
from tensorflow.keras.preprocessing.image import load_img, img_to_array
import numpy as np
from PIL import Image
import io
st.set_page_config(
page_title="Waste Classifier",
layout="centered"
)
@st.cache_resource
def load_model():
return tf.keras.models.load_model('CNN_Prak4_ML.h5')
def preprocess_image(img):
img = img.resize((244, 244))
img = img_to_array(img)
img = np.expand_dims(img, axis=0)
img = img / 255.0
return img
LABEL_CLASS = {
0: "Cardboard",
1: "Glass",
2: "Metal",
3: "Paper",
4: "Textile Trash",
5: "Vegetation"
}
def main():
st.title("Waste Classifier")
st.write("Upload an image and the model will predict whether it's a chihuahua or a muffin!")
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
if uploaded_file is not None:
image = Image.open(uploaded_file)
st.image(image, caption='Uploaded Image', use_column_width=True)
if st.button('Predict'):
model = load_model()
processed_image = preprocess_image(image)
with st.spinner('Predicting...'):
prediction = model.predict(processed_image)
pred_class = LABEL_CLASS[np.argmax(prediction)]
confidence = float(prediction.max()) * 100
st.success(f'Prediction: {pred_class.upper()}')
st.info(f'Confidence: {confidence:.2f}%')
st.write("Class Probabilities:")
for i, prob in enumerate(prediction[0]):
st.progress(float(prob))
st.write(f"{LABEL_CLASS[i]}: {float(prob)*100:.2f}%")
if __name__ == "__main__":
>>>>>>> 9014ce89a3d5b013b1a3e93a65c21b8e932a0117 main()12345678<<<<<<< HEADpillow==10.4.0streamlit==1.39.0=======pillow==10.4.0
streamlit==1.39.0
>>>>>>> 9014ce89a3d5b013b1a3e93a65c21b8e932a0117tensorflow==2.18.0CNN_Prak4_ML.h5Added+3
app.pyAdded+128
requirement.txtAdded+8