-
Notifications
You must be signed in to change notification settings - Fork 0
/
streamlit_app.py
78 lines (64 loc) · 3.19 KB
/
streamlit_app.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import streamlit as st
import tensorflow as tf
from tensorflow.keras.models import load_model
from tensorflow import keras
loaded_model = load_model('my_model.h5')
def process_image(image):
# with keras
img = keras.preprocessing.image.load_img(image, target_size=(32, 32))
img = keras.preprocessing.image.img_to_array(img)
# expected shape=(None, 224, 224, 3)
img = tf.image.resize(img, [32, 32])
img = img / 255.0
img = tf.expand_dims(img, axis=0)
return img
# Sidebar for navigation
st.sidebar.title('Navigation')
options = st.sidebar.selectbox('Select a page:',
['Prediction', 'Code', 'About'])
if options == 'Prediction': # Prediction page
st.title('Object Recognition using ResNet50')
# User inputs: image
image = st.file_uploader('Upload an image:', type=['jpg', 'jpeg', 'png'])
if image is not None:
st.image(image, caption='Uploaded Image', use_column_width=True)
# preds = ['airplane' 'automobile' 'bird' 'cat' 'deer' 'dog' 'frog' 'horse' 'ship''truck']
preds = ['Airplane', 'Automobile', 'Bird', 'Cat', 'Deer', 'Dog', 'Frog', 'Horse', 'Ship', 'Truck']
if st.button('Predict'):
with st.spinner('Model working....'):
img_array = process_image(image)
prediction = loaded_model.predict(img_array).argmax()
st.success(f'The image is a {preds[prediction]}')
elif options == 'Code':
st.header('Code')
# Add a button to download the Jupyter notebook (.ipynb) file
notebook_path = 'object_recognition_model.ipynb'
with open(notebook_path, "rb") as file:
btn = st.download_button(
label="Download Jupyter Notebook",
data=file,
file_name="object_recognition_model.ipynb",
mime="application/x-ipynb+json"
)
st.write('You can download the Jupyter notebook to view the code and the model building process.')
st.write('--'*50)
st.header('GitHub Repository')
st.write('You can view the code and the dataset used in this web app from the GitHub repository:')
st.write('[GitHub Repository](https://github.com/gokulnpc/Object-Recognition-ResNet50)')
st.write('--'*50)
elif options == 'About':
st.title('About')
st.write('This is a web app to predict the object in an image using the ResNet50 model.')
st.write('The ResNet50 model is a pre-trained model on the ImageNet dataset.')
st.write('The model is trained to classify 10 different objects.')
# preds = ['Airplane', 'Automobile', 'Bird', 'Cat', 'Deer', 'Dog', 'Frog', 'Horse', 'Ship', 'Truck']
st.write('The objects are: Airplane, Automobile, Bird, Cat, Deer, Dog, Frog, Horse, Ship, Truck')
st.write('--'*50)
st.write('The web app is open-source. You can view the code and the dataset used in this web app from the GitHub repository:')
st.write('[GitHub Repository](https://github.com/gokulnpc/Object-Recognition-ResNet50)')
st.write('--'*50)
st.header('Contact')
st.write('You can contact me for any queries or feedback:')
st.write('Email: [email protected]')
st.write('LinkedIn: [Gokuleshwaran Narayanan](https://www.linkedin.com/in/gokulnpc/)')
st.write('--'*50)