File size: 849 Bytes
9e03531
18803aa
 
 
9e03531
18803aa
 
 
e00b9d5
 
 
 
 
 
 
 
98195dd
18803aa
 
 
 
 
98195dd
18803aa
98195dd
03914c0
98195dd
18803aa
 
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
27
28
29
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, ': ', round(predictions[p] * 100, 1))
        #col2.subheader(f"{ p['label'] }: { round(p['probs'] * 100, 1)}%")
else:
    st.write('Please upload a file!')