File size: 700 Bytes
6a9cdf6
 
615db94
6a9cdf6
511270d
 
 
 
 
 
6a9cdf6
 
 
 
 
 
 
 
 
 
 
615db94
6a9cdf6
 
 
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
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)