import streamlit as st from fastai.vision.all import * import matplotlib.pyplot as plt import pandas as pd 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): temp_folder = "tmp" if not os.path.exists(temp_folder): os.makedirs(temp_folder) path_name = os.path.join(temp_folder,uploadedfile.name) with open(path_name,"wb") as f: f.write(uploadedfile.getbuffer()) return path_name st.write(""" # Dog vs Cat Classifier This is a application that classifies images of dogs vs cats """) 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)) preds = pd.DataFrame(classify_image(path_name), index=[0]) st.bar_chart(preds)