gmustafa413 commited on
Commit
5855c83
·
verified ·
1 Parent(s): 6a34b34

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py CHANGED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ import streamlit as st
3
+ import tensorflow as tf
4
+ from tensorflow.keras.models import load_model
5
+ import numpy as np
6
+ from PIL import Image
7
+
8
+ # Load the pre-trained model
9
+ model = load_model("cifar10_cnn_model.h5")
10
+
11
+ # Class names for CIFAR-10 dataset
12
+ class_names = ['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck']
13
+
14
+ # Streamlit app title
15
+ st.title("CIFAR-10 Image Classification")
16
+
17
+ # Upload image
18
+ uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
19
+
20
+ if uploaded_file is not None:
21
+ # Display the uploaded image
22
+ image = Image.open(uploaded_file)
23
+ st.image(image, caption="Uploaded Image", use_column_width=True)
24
+
25
+ # Preprocess the image
26
+ image = image.resize((32, 32)) # Resize to match CIFAR-10 input size
27
+ image = np.array(image) / 255.0 # Normalize pixel values
28
+ image = np.expand_dims(image, axis=0) # Add batch dimension
29
+
30
+ # Make prediction
31
+ predictions = model.predict(image)
32
+ predicted_class = np.argmax(predictions)
33
+ confidence = np.max(predictions) * 100
34
+
35
+ # Display results
36
+ st.write(f"**Prediction:** {class_names[predicted_class]}")
37
+ st.write(f"**Confidence:** {confidence:.2f}%")