mahmohajer's picture
fixing the typos
615db94
raw
history blame contribute delete
700 Bytes
import gradio as gr
from fastai.vision.all import *
import re
def label_func(fname):
pattern = r'(FRESH|HALF-FRESH|SPOILED)-\d+-'
match = re.search(pattern, fname.name)
if match:
label = match.group(1)
return label
learn = load_learner("model.pkl")
categories = ('Fresh', 'Half-fresh', 'Spoiled')
def classify_image(img):
pred, idx, probs = learn.predict(img)
return dict(zip(categories, map(float, probs)))
image = gr.Image(height=280, width=340, type='numpy')
label = gr.Label()
examples = ['fresh.jpg', 'semi-fresh.jpg', 'rotten meat.jpeg']
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)