fast_ai_models / app.py
jph00's picture
update
4d6cfb5
raw
history blame
824 Bytes
import streamlit as st
from fastai.vision.all import *
def is_cat(x) : return x[0].isupper()
learn = load_learner('model.pkl')
categories = ('Dog', 'Cat')
def classify_image(img):
pred,idx,probs = learn.predict(img)
return dict(zip(categories,map(float,probs)))
def save_uploaded_file(uploadedfile):
path_name = os.path.join("tmp",uploadedfile.name)
with open(path_name,"wb") as f:
f.write(uploadedfile.getbuffer())
st.success(f"Saved file :{uploadedfile.name} as {path_name}")
return path_name
upload_image = st.file_uploader("Choose a file")
if upload_image is not None:
image = PILImage.create(upload_image)
image.thumbnail((192,192))
st.image(image)
path_name = save_uploaded_file(upload_image)
st.write("Prediction Propabilities:")
st.write(classify_image(path_name))