Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
# Load the model
|
| 7 |
+
model = tf.keras.models.load_model("cifar10_saved_model")
|
| 8 |
+
|
| 9 |
+
# CIFAR-10 class names
|
| 10 |
+
class_names = [
|
| 11 |
+
"Airplane", "Automobile", "Bird", "Cat", "Deer",
|
| 12 |
+
"Dog", "Frog", "Horse", "Ship", "Truck"
|
| 13 |
+
]
|
| 14 |
+
|
| 15 |
+
# Streamlit app layout
|
| 16 |
+
st.title("CIFAR-10 Image Classifier")
|
| 17 |
+
st.write("Upload an image to classify it into one of the CIFAR-10 categories.")
|
| 18 |
+
|
| 19 |
+
# File uploader
|
| 20 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
|
| 21 |
+
|
| 22 |
+
if uploaded_file:
|
| 23 |
+
# Preprocess the uploaded image
|
| 24 |
+
image = Image.open(uploaded_file).resize((32, 32))
|
| 25 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 26 |
+
|
| 27 |
+
# Convert image to array
|
| 28 |
+
img_array = np.array(image) / 255.0 # Normalize
|
| 29 |
+
img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
|
| 30 |
+
|
| 31 |
+
# Predict
|
| 32 |
+
with st.spinner("Classifying..."):
|
| 33 |
+
predictions = model.predict(img_array)
|
| 34 |
+
predicted_class = class_names[np.argmax(predictions)]
|
| 35 |
+
confidence = np.max(predictions)
|
| 36 |
+
|
| 37 |
+
# Display results
|
| 38 |
+
st.success(f"Prediction: {predicted_class}")
|
| 39 |
+
st.info(f"Confidence: {confidence:.2f}")
|