File size: 926 Bytes
d13656f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
26
27
28
29
30
31
import gradio as gr
from fastai.vision.all import *
import skimage

learn = load_learner('model.pkl')

# Original labels from the model
labels = learn.dls.vocab

# Custom mapping for labels
custom_labels = {
    "Other": "Nimeshindwa kutambua picha",
    "lateblt": "Ukungu wa mwisho wa viazi",
    "earlyblt": "Ukungu wa mwanzo wa viazi",
    "healthy": "Jani halina ugonjwa"
}

def predict(img):
    img = PILImage.create(img)
    pred, pred_idx, probs = learn.predict(img)
    # Map the model's labels to the custom labels
    return {custom_labels[labels[i]]: float(probs[i]) for i in range(len(labels))}

# Other parameters
examples = ['image.jpg']
interpretation = 'default'
enable_queue = True

# Launch Gradio interface
gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), outputs=gr.outputs.Label(num_top_classes=3), examples=examples, interpretation=interpretation, enable_queue=enable_queue).launch()