-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
46 lines (38 loc) · 1.29 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
import streamlit as st
import os
from PIL import Image
from helper import *
st.title('Dogs vs Cats Classifier')
def save_uploaded_file(up_file):
"""This function saves the uploaded pics to the static/images folder.
Parameters:
-----------
up_file: Uploaded image file
Returns:
---------
1, file path if successful and 0 if failed"""
try:
with open(os.path.join('static\images', up_file.name), 'wb') as file:
file.write(uploaded_file.getbuffer())
#print('file written')
return 1
except:
return 0
# Creating Upload button,
# display uploaded image on the app,
# and call the predictor function which we had just created.
uploaded_file = st.file_uploader("Upload Image Here")
#print(uploaded_file)
print(save_uploaded_file(uploaded_file))
if uploaded_file is not None:
if save_uploaded_file(uploaded_file):
display_image = Image.open(uploaded_file)
st.image(display_image)
prediction = get_prediction(os.path.join('static\images', uploaded_file.name))
#print(prediction)
# delete uploaded file after prediction
os.remove(os.path.join('static\images', uploaded_file.name))
if prediction:
st.write('Dog Detected')
else:
st.write('Cat Detected')