-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
49 lines (39 loc) · 1.71 KB
/
app.py
File metadata and controls
49 lines (39 loc) · 1.71 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
38
39
40
41
42
43
44
45
46
47
48
49
# app.py
import streamlit as st
import tensorflow as tf
from tensorflow.keras.models import load_model
import numpy as np
from PIL import Image
# Load the trained model
model = load_model("cifar10_cnn_model.keras")
# CIFAR-10 classes
classes = ['airplane','automobile','bird','cat','deer','dog','frog','horse','ship','truck']
# Streamlit page config
st.set_page_config(page_title="CIFAR-10 Image Classification", page_icon="📷")
st.title("📷 Image Classification App")
st.write("Upload an image and the model will predict its class.")
st.write("Add only airplane, automobile, bird, cat, deer, dog, frog, horse, ship, truck Images")
# Sidebar info
st.sidebar.header("About the Project")
st.sidebar.info("""
**Created by:** Mirza Yasir Abdullah Baig
- [LinkedIn](https://www.linkedin.com/in/mirza-yasir-abdullah-baig/)
- [Kaggle](https://www.kaggle.com/code/mirzayasirabdullah07)
- [GitHub](https://github.com/mirzayasirabdullahbaig07)
This project classifies images into 10 CIFAR-10 categories.
""")
# Image upload
uploaded_file = st.file_uploader("Choose an image...", type=["jpg","jpeg","png"])
if uploaded_file is not None:
# Open and display the image
image = Image.open(uploaded_file).convert("RGB")
st.image(image, caption='Uploaded Image', use_container_width=True)
# Preprocess image
img = image.resize((32, 32))
img_array = np.array(img)/255.0
img_array = np.expand_dims(img_array, axis=0) # Shape (1, 32, 32, 3)
# Predict
prediction = model.predict(img_array)
predicted_class = classes[np.argmax(prediction)]
st.subheader("Prediction")
st.write(f"The uploaded image is classified as: **{predicted_class}**")