File size: 1,112 Bytes
5514c44
 
 
 
 
f29298a
5514c44
 
 
 
 
 
 
 
f29298a
 
 
 
 
be0aedc
 
5514c44
be0aedc
5514c44
 
 
 
 
 
be0aedc
5514c44
 
 
 
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
32
33
34
import streamlit as st
import pandas as pd
from fastai import *
from fastai.vision.all import *
import pickle
import pathlib

header = st.container()
inference = st.container()

with header:
	st.title("Cuisine Classifier")
	st.text("Is your food Italian, French, Chinese, Indian, or Japanese?")

with inference:    
    plt = platform.system()
    if plt == 'Linux':
        pathlib.WindowsPath = pathlib.PosixPath
        
    path = Path()
    path.ls(file_exts='.pkl')

    learn_inf = load_learner(path/'export.pkl')

    st.header('Show me your food pic!')
    st.text("(I currently accept Italian, French, Chinese, Indian, or Japanese. Otherwise, I guesss wildly!)")
    uploaded_file = st.file_uploader("Show me your food pic!")    
    if uploaded_file is not None:
        img = load_image(uploaded_file)
        #img = PILImage.create(uploaded_file)
        pred, pred_idx, probs = learn_inf.predict(img)
        prob_value = probs[pred_idx].item()
        rounded_prob_percentage = round(prob_value * 100)
        st.text(f"This is {pred}, isn't it? Believe me, I am {rounded_prob_percentage}% sure!")