Biswa000 commited on
Commit
ec2844c
·
verified ·
1 Parent(s): bbdd4d5

2nd update

Browse files
Files changed (1) hide show
  1. app.py +12 -7
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
- predicted_class = class_names[np.argmax(predictions)]
19
- return predicted_class
 
 
 
20
 
21
- iface = gr.Interface(fn=predict_rice_disease,
22
- inputs=gr.Image(type="pil"),
23
- outputs="text",
24
- title="Rice Disease Classifier")
 
 
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()