File size: 824 Bytes
4d6cfb5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from fastai.vision.all import *

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):
  path_name = os.path.join("tmp",uploadedfile.name)
  with open(path_name,"wb") as f:
    f.write(uploadedfile.getbuffer())
    st.success(f"Saved file :{uploadedfile.name} as {path_name}")
  return path_name

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))