fastai-pets / app.py
ptah23's picture
testing
2fd2a2e
import numpy as np
import streamlit as st
from fastai.vision.core import *
from fastai.vision.all import *
import pathlib
import platform
if platform.system() == 'Windows':
temp = pathlib.PosixPath
pathlib.PosixPath = pathlib.WindowsPath
def is_cat(x): return x[0].isupper()
if __name__=='__main__':
learn = load_learner(pathlib.Path()/'model.pkl')
uploaded_file = st.file_uploader("Choose an image of a dog or cat")
if uploaded_file is not None:
im = PILImage.create((uploaded_file))
st.image(im.to_thumb(500, 500), caption='Uploaded Image')
if st.button('Classify'):
pred, ix, probs = learn.predict(im.convert('RGB'))
data = dict(zip(('Dog', 'Cat'), map(float, probs)))
st.bar_chart(data=data)
else:
st.write(f'Click the button to classify')