Spaces:
Sleeping
Sleeping
File size: 847 Bytes
2fd2a2e |
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 |
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')
|