Qudrat0708's picture
Update app.py
fae3cf9 verified
import streamlit as st
import tensorflow as tf
import numpy as npv
from PIL import Image
# Load the model
model = tf.keras.models.load_model("cifar10_cnn_model.h5")
# CIFAR-10 class names
class_names = [
"Airplane", "Automobile", "Bird", "Cat", "Deer",
"Dog", "Frog", "Horse", "Ship", "Truck"
]
# Streamlit app layout
st.title("CIFAR-10 Image Classifier")
st.write("Upload an image to classify it into one of the CIFAR-10 categories.")
# File uploader
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
if uploaded_file:
# Preprocess the uploaded image
image = Image.open(uploaded_file).resize((32, 32))
st.image(image, caption="Uploaded Image", use_column_width=True)
# Convert image to array
img_array = np.array(image) / 255.0 # Normalize
img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
# Predict
with st.spinner("Classifying..."):
predictions = model.predict(img_array)
predicted_class = class_names[np.argmax(predictions)]
confidence = np.max(predictions)
# Display results
st.success(f"Prediction: {predicted_class}")
st.info(f"Confidence: {confidence:.2f}")