-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
94 lines (83 loc) · 3.02 KB
/
main.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# -*- coding: utf-8 -*-
"""
Created on Mon Jul 27 08:04:26 2020
@author: jai ganesh
"""
#importing required libraries
import tensorflow
import io
import os
import numpy as np
import keras
from PIL import Image , ImageOps
from keras.preprocessing.image import load_img
from keras.preprocessing.image import img_to_array
from keras.applications.xception import preprocess_input
from keras.applications.xception import decode_predictions
from keras.models import load_model
import streamlit as st
from werkzeug.utils import secure_filename
import h5py
#loading model
model = load_model('xception_model')
model._make_predict_function()
def predict(image1):
image = image1
size=(299,299) #for xception it expects 299x299 size
image = ImageOps.fit(image, size)
# convert the image pixels to a numpy array
image = img_to_array(image)
# reshape data for the model
image = image.reshape((1, image.shape[0], image.shape[1], image.shape[2]))
# prepare the image for the xception model
image = preprocess_input(image)
# predict the probability across all output classes
yhat = model.predict(image)
# convert the probabilities to class labels
label = decode_predictions(yhat)
# retrieve the most likely result, e.g. highest probability
label = label[0][0]
return label
#main page
def main():
st.title("Image Guessing Application")
html_temp2 ="""
<div style="padding:5px">
<h6 style="color:green;text-align:right;font-weight:bold;font-style:verdana;">created by ©jai ganesh Nagidi</h6>
</div>
"""
st.markdown(html_temp2,unsafe_allow_html=True)
html_temp="""
<div style="background-color:purple;padding:10px">
<h2 style="color:white;text-align:center;">Let's Classifiy 😊😎</h2>
</div>
"""
st.markdown(html_temp,unsafe_allow_html=True)
st.set_option('deprecation.showfileUploaderEncoding',False)
uploaded_file = st.file_uploader("Choose an image...",type=['jpg','png','jpeg'])
if uploaded_file is not None:
image = Image.open(uploaded_file)
st.image(image, caption='Uploaded Image.', use_column_width=True)
if st.button("Predict"):
if uploaded_file is None:
raise Exception("image not uploaded, please refresh page and upload the image")
st.write("")
st.write("Classifying...")
label = predict(image)
st.write('%s (%.2f%%)' % (label[1], label[2]*100))
hide_streamlit_style ="""
<style>
#MainMenu {visibility: hidden;}
footer {visibility: hidden;}
</style>
"""
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
html_temp3="""
<p>This application can able to detect 1000+ different objects.This application was developed by © Jai Ganesh Naigidi<br>
you can connect with him :<a href="https://www.linkedin.com/in/jaiganesh-nagidi-4205a4181/">Let's connect</a>
</p>
"""
if st.button("About"):
st.markdown(html_temp3,unsafe_allow_html=True)
if __name__=='__main__':
main()