project21 commited on
Commit
e826e7e
·
verified ·
1 Parent(s): 8ed83e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -0
app.py CHANGED
@@ -33,6 +33,19 @@ def predict_disease(image_file, model, all_labels, target_language):
33
 
34
  # Predict the class
35
  predictions = model.predict(img_array)
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  predicted_class = np.argmax(predictions[0])
37
 
38
  # Get the predicted class label
 
33
 
34
  # Predict the class
35
  predictions = model.predict(img_array)
36
+ confidence_threshold = 0.98 # Require at least 98% confidence
37
+ confidence_scores = predictions[0]
38
+ max_confidence = np.max(confidence_scores)
39
+
40
+ if max_confidence < confidence_threshold:
41
+ print(f"Prediction confidence ({max_confidence:.2f}) is too low.")
42
+ return f"""
43
+ <h3 style="color:red; text-align:center;">
44
+ The model's confidence is below 98% ({max_confidence*100:.2f}%).
45
+ Please upload a clearer image of the plant.
46
+ </h3>
47
+ """
48
+
49
  predicted_class = np.argmax(predictions[0])
50
 
51
  # Get the predicted class label