Spaces:
Build error
Build error
Files Uploaded
Browse files- app.py +79 -0
- cnn_model.h5 +3 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from tensorflow.keras.models import load_model
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import numpy as np
|
| 5 |
+
import pandas as pd
|
| 6 |
+
|
| 7 |
+
model = load_model('cnn_model.h5')
|
| 8 |
+
|
| 9 |
+
def process_image(img):
|
| 10 |
+
img = img.resize((32, 32))
|
| 11 |
+
img = np.array(img)
|
| 12 |
+
img = img / 255.0
|
| 13 |
+
img = np.expand_dims(img, axis=0)
|
| 14 |
+
return img
|
| 15 |
+
|
| 16 |
+
st.markdown("""
|
| 17 |
+
<style>
|
| 18 |
+
.title {
|
| 19 |
+
font-size: 50px;
|
| 20 |
+
color: #A8D5FF; # Pastel Blue color
|
| 21 |
+
font-weight: bold;
|
| 22 |
+
text-align: center;
|
| 23 |
+
}
|
| 24 |
+
.description {
|
| 25 |
+
font-size: 16px;
|
| 26 |
+
color: #555555;
|
| 27 |
+
text-align: center;
|
| 28 |
+
}
|
| 29 |
+
.uploaded-image {
|
| 30 |
+
display: block;
|
| 31 |
+
margin-left: auto;
|
| 32 |
+
margin-right: auto;
|
| 33 |
+
padding: 20px;
|
| 34 |
+
}
|
| 35 |
+
.prediction {
|
| 36 |
+
font-size: 20px;
|
| 37 |
+
font-weight: bold;
|
| 38 |
+
text-align: center;
|
| 39 |
+
}
|
| 40 |
+
.confidence {
|
| 41 |
+
font-size: 18px;
|
| 42 |
+
text-align: center;
|
| 43 |
+
color: #4CAF50;
|
| 44 |
+
}
|
| 45 |
+
.bar-chart {
|
| 46 |
+
text-align: center;
|
| 47 |
+
}
|
| 48 |
+
</style>
|
| 49 |
+
""", unsafe_allow_html=True)
|
| 50 |
+
|
| 51 |
+
st.markdown('<div class="title">CIFAR-10 Image Classification 🔎</div>', unsafe_allow_html=True)
|
| 52 |
+
st.markdown('<div class="description">Upload an image to classify it into one of the CIFAR-10 categories.</div>', unsafe_allow_html=True)
|
| 53 |
+
|
| 54 |
+
file = st.file_uploader('Upload an image', type=['jpg', 'jpeg', 'png'])
|
| 55 |
+
|
| 56 |
+
if file is not None:
|
| 57 |
+
img = Image.open(file)
|
| 58 |
+
st.markdown('<div class="uploaded-image">', unsafe_allow_html=True)
|
| 59 |
+
st.image(img, caption='Uploaded Image', use_column_width=True, output_format='PNG')
|
| 60 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 61 |
+
|
| 62 |
+
with st.spinner('Processing...'):
|
| 63 |
+
image = process_image(img)
|
| 64 |
+
predictions = model.predict(image)
|
| 65 |
+
predicted_class = np.argmax(predictions)
|
| 66 |
+
class_names = ['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck']
|
| 67 |
+
|
| 68 |
+
confidence = np.max(predictions) * 100 # Confidence score
|
| 69 |
+
|
| 70 |
+
st.markdown(f'<div class="prediction">Prediction: {class_names[predicted_class]}</div>', unsafe_allow_html=True)
|
| 71 |
+
st.markdown(f'<div class="confidence">Confidence: {confidence:.2f}%</div>', unsafe_allow_html=True)
|
| 72 |
+
|
| 73 |
+
st.markdown('<div class="bar-chart">Class Probabilities:</div>', unsafe_allow_html=True)
|
| 74 |
+
prob_df = pd.DataFrame(predictions[0], index=class_names, columns=["Probability"])
|
| 75 |
+
st.bar_chart(prob_df)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
st.markdown('---')
|
| 79 |
+
st.markdown("<div style='text-align: center;'>Powered by Streamlit and TensorFlow</div>", unsafe_allow_html=True)
|
cnn_model.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:75ae33cd1a6e220fdbe563473e986b4dd59f800916865506f0acca7ae4a40e43
|
| 3 |
+
size 17545776
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
tensorflow
|