Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from fastai.vision.all import *
|
| 3 |
+
import skimage
|
| 4 |
+
|
| 5 |
+
learn = load_learner('model.pkl')
|
| 6 |
+
|
| 7 |
+
labels = learn.dls.vocab
|
| 8 |
+
|
| 9 |
+
custom_labels = {
|
| 10 |
+
"Other": "Nimeshindwa kutambua picha",
|
| 11 |
+
"rust": "Kutu ya majani ya Maharage",
|
| 12 |
+
"anthra": "Ndui ya maharage",
|
| 13 |
+
"healthy": "Mmea una afya"
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
def predict(img):
|
| 17 |
+
img = PILImage.create(img)
|
| 18 |
+
pred, pred_idx, probs = learn.predict(img)
|
| 19 |
+
return {custom_labels[labels[i]]: float(probs[i]) for i in range(len(labels))}
|
| 20 |
+
|
| 21 |
+
examples = ['image.jpg']
|
| 22 |
+
interpretation = 'default'
|
| 23 |
+
enable_queue = True
|
| 24 |
+
|
| 25 |
+
# Updated component usage
|
| 26 |
+
gr.Interface(fn=predict, inputs=gr.components.Image(), outputs=gr.components.Label(num_top_classes=3), examples=examples).launch()
|