tasmay's picture
modified model
e064d78
raw
history blame
860 Bytes
import streamlit as st
from PIL import Image
from fastai.vision.all import *
import pickle
st.title("Piano or Keyboard?")
file_name = st.file_uploader("Upload a piano or a keyboard image")
# model = pickle.load(open('export.pkl','rb'))
model = load_learner('export.pkl')
labels = model.dls.vocab
def predict(img):
img = PILImage.create(img)
pred,pred_idx,probs = model.predict(img)
return dict(zip(labels, map(float, probs)))
if file_name is not None:
col1, col2 = st.columns(2)
image = Image.open(file_name)
col1.image(image, use_column_width=True)
predictions = predict(file_name)
col2.header("Prediction:")
for p in predictions:
st.write(p, ': ', predictions[p])
print(predictions)
#col2.subheader(f"{ p['label'] }: { round(p['probs'] * 100, 1)}%")
else:
st.write('Please upload a file!')