File size: 898 Bytes
16deb46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1c917f0
16deb46
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import timm
import gradio as gr
from pathlib import Path
from fastai.vision.all import *

categories = ['Tomato___Bacterial_spot', 'Tomato___Early_blight', 'Tomato___Late_blight', 'Tomato___Leaf_Mold', 'Tomato___Septoria_leaf_spot', 'Tomato___Spider_mites Two-spotted_spider_mite', 'Tomato___Target_Spot', 'Tomato___Tomato_Yellow_Leaf_Curl_Virus', 'Tomato___Tomato_mosaic_virus', 'Tomato___healthy']

learner = load_learner(Path('tomato_resnet50.pkl'))

def classify(img):
    category, index, probs = learner.predict(img)
    return (dict(zip(categories, map(float, probs))))

image = gr.inputs.Image(shape=(224))
label = gr.outputs.Label()
example = ['Tomato___Bacterial_spot.JPG', 'Tomato___Early_blight.JPG']

interface = gr.Interface(fn=classify, 
                         inputs='image', 
                         outputs='label',
                         example=example)

interface.launch()