File size: 894 Bytes
9e03531
18803aa
 
 
9e03531
18803aa
 
 
e00b9d5
 
 
 
 
 
 
 
98195dd
18803aa
 
 
 
 
b80c638
 
18803aa
98195dd
e064d78
b80c638
 
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
30
31
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!')