sw_irishpotato / app.py
devdata's picture
Create app.py
d13656f
raw
history blame
926 Bytes
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()