File size: 825 Bytes
aa605e6
cf2032a
aa605e6
 
0c21dc2
aa605e6
70637f0
aa605e6
 
 
 
 
 
 
 
 
 
c6d1564
a128649
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from fastai.vision.all import *
import timm 
import gradio as gr

learn = load_learner('bean.pkl')

categories = ('Black Beans', 'Chickpea', 'Coffee Bean', 'Kidney Beans', 'Ligma Beans', 'Soybean')
# Gradio requires a dictionary of all the categories and the probabilities of each category. 
def classify_image(img):
    pred, idx, probs = learn.predict(img)
    return dict(zip(categories, map(float, probs)))

image = gr.components.Image(shape=(192, 192))
label = gr.outputs.Label()
examples = ['coffee.jpg', 'kidney.jpg', 'soybean.jpg', 'fresh coffee bean.jpg']

intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)

# When uploading to Huggingspaces we dont need to specify the WindowsPath. That was just for Jupyter, some weird errors with my python software.