2nd update
Browse files
app.py
CHANGED
|
@@ -14,13 +14,18 @@ def predict_rice_disease(img):
|
|
| 14 |
img = img.resize((224, 224))
|
| 15 |
img_array = image.img_to_array(img) / 255.0
|
| 16 |
img_array = np.expand_dims(img_array, axis=0)
|
| 17 |
-
predictions = model.predict(img_array)
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
iface = gr.Interface(
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
|
| 26 |
iface.launch()
|
|
|
|
| 14 |
img = img.resize((224, 224))
|
| 15 |
img_array = image.img_to_array(img) / 255.0
|
| 16 |
img_array = np.expand_dims(img_array, axis=0)
|
| 17 |
+
predictions = model.predict(img_array)[0] # shape: (num_classes,)
|
| 18 |
+
|
| 19 |
+
# Map class names to confidence scores
|
| 20 |
+
confidence_scores = {class_names[i]: float(f"{predictions[i]:.4f}") for i in range(len(class_names))}
|
| 21 |
+
|
| 22 |
+
return confidence_scores
|
| 23 |
|
| 24 |
+
iface = gr.Interface(
|
| 25 |
+
fn=predict_rice_disease,
|
| 26 |
+
inputs=gr.Image(type="pil"),
|
| 27 |
+
outputs=gr.Label(num_top_classes=len(class_names)), # shows all class scores nicely
|
| 28 |
+
title="Rice Disease Classifier"
|
| 29 |
+
)
|
| 30 |
|
| 31 |
iface.launch()
|