-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
29 lines (23 loc) · 945 Bytes
/
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
import streamlit as st
from fastai.vision.all import *
from utils import download_from_gdrive
def load_learner_(path):
return load_learner(path)
def load_img(path):
image = Image.open(path)
w, h = image.size
dim = (500, int((h*500)/w))
return image.resize(dim)
st.markdown("# Animal Classifier")
st.markdown("Upload an image and the classifier will tell you whether its a horse, dog or bear.")
with st.spinner('Downloading model...'):
download_from_gdrive(file_id='1L7Q0swWYEpdDUw8T4ho0kto-1k5fkUZS', dest_path='./export.pkl')
learn = load_learner_('export.pkl')
file_bytes = st.file_uploader("Upload a file", type=("png", "jpg", "jpeg", "jfif"))
if file_bytes:
img = load_img(file_bytes)
st.image(img)
submit = st.button('Predict!')
if submit:
pred, pred_idx, probs = learn.predict(PILImage(img))
st.markdown(f'Prediction: **{pred}**; Probability: **{probs[pred_idx]:.04f}**')