-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
60 lines (50 loc) · 1.85 KB
/
Copy pathapp.py
File metadata and controls
60 lines (50 loc) · 1.85 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
50
51
52
53
54
55
56
57
58
59
60
import streamlit as st
import tensorflow as tf
from keras.preprocessing import image # type: ignore
import numpy as np
import warnings
warnings.filterwarnings("ignore")
# setting up the page header here.
hide_st_style = """
<style>
#MainMenu {visibility : hidden;}
footer {visibility : hidden;}
header {visibility : hidden;}
</style>
"""
# setting up the page config here.
st.set_page_config(
page_title="DogCat CNN Classifier",
page_icon="😽",
layout="centered",
initial_sidebar_state="expanded",
menu_items={
'Get Help': 'https://www.linkedin.com/in/abhiiiman',
'Report a bug': "https://www.github.com/abhiiiman",
'About': "## Basic CNN App to classfiy Dog or Cat"
}
)
# removing all the default streamlit configs here
st.markdown(hide_st_style, unsafe_allow_html=True)
# Load the trained model
model = tf.keras.models.load_model(r'model.h5')
# Function to make a prediction
def make_prediction(uploaded_file):
img = image.load_img(uploaded_file, target_size=(64, 64))
img_array = image.img_to_array(img)
img_array = np.expand_dims(img_array, axis=0)
img_array /= 255.0
result = model.predict(img_array)
return 'dog' if result[0][0] > 0.5 else 'cat'
# Streamlit app
st.title("Cat or Dog Classifier 🐕🐈")
st.markdown("##### Upload an image and the model will predict whether it's a cat or a dog.")
st.markdown("* `92% Accuracy`⚡")
uploaded_file = st.file_uploader("Choose an image 🖼️", type="jpg")
if uploaded_file is not None:
st.image(uploaded_file, caption='Uploaded Image.', use_column_width=True)
prediction = make_prediction(uploaded_file)
if prediction == 'dog':
st.markdown("### I can see, it's a Dog 🐶")
else:
st.markdown("### Okay so, it's a Cat 😽")