Spaces:
Sleeping
Sleeping
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) | |
with st.spinner('Wait for it...'): | |
predictions = predict(file_name) | |
col2.header("Prediction:") | |
for p in predictions: | |
print(predictions) | |
perecent_pred = round(predictions[p] * 100, 1) | |
col2.subheader(f"{ p }: { perecent_pred }%") | |
else: | |
st.write('Please upload a file!') |