cool / app.py
zhucch
fixed alpha
70637f0
raw
history blame contribute delete
825 Bytes
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.