Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,16 +5,31 @@ import skimage
|
|
| 5 |
learn = load_learner('model.pkl')
|
| 6 |
|
| 7 |
labels = learn.dls.vocab
|
|
|
|
| 8 |
def predict(img):
|
| 9 |
img = PILImage.create(img)
|
| 10 |
-
pred,pred_idx,probs = learn.predict(img)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 12 |
|
| 13 |
-
title = "Common beans diseases
|
| 14 |
-
description = "An app for Common beans diseases
|
| 15 |
-
article="<p style='text-align: center'>The app identifies and classifies common beans diseases: Anthracnose and Bean rust.</p>"
|
| 16 |
examples = ['image.jpeg']
|
| 17 |
-
interpretation='default'
|
| 18 |
-
enable_queue=True
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
learn = load_learner('model.pkl')
|
| 6 |
|
| 7 |
labels = learn.dls.vocab
|
| 8 |
+
|
| 9 |
def predict(img):
|
| 10 |
img = PILImage.create(img)
|
| 11 |
+
pred, pred_idx, probs = learn.predict(img)
|
| 12 |
+
|
| 13 |
+
# Check if the predicted label is 'Other'
|
| 14 |
+
if pred == 'Other':
|
| 15 |
+
return 'The model can\'t recognize the image, adjust your camera angle and take a close picture of a leaf'
|
| 16 |
+
|
| 17 |
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 18 |
|
| 19 |
+
title = "Common beans diseases classifier"
|
| 20 |
+
description = "An app for Common beans diseases Classification"
|
| 21 |
+
article = "<p style='text-align: center'>The app identifies and classifies common beans diseases: Anthracnose and Bean rust.</p>"
|
| 22 |
examples = ['image.jpeg']
|
| 23 |
+
interpretation = 'default'
|
| 24 |
+
enable_queue = True
|
| 25 |
|
| 26 |
+
# Modify the output to Textbox to handle string messages as well
|
| 27 |
+
gr.Interface(fn=predict,
|
| 28 |
+
inputs=gr.inputs.Image(shape=(512, 512)),
|
| 29 |
+
outputs=gr.outputs.Textbox(),
|
| 30 |
+
title=title,
|
| 31 |
+
description=description,
|
| 32 |
+
article=article,
|
| 33 |
+
examples=examples,
|
| 34 |
+
interpretation=interpretation,
|
| 35 |
+
enable_queue=enable_queue).launch()
|