bhanusAI commited on
Commit
bef811e
·
verified ·
1 Parent(s): 49183b2
Files changed (1) hide show
  1. app.py +24 -16
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import numpy as np
2
  import gradio as gr
3
  import tensorflow as tf # version 2.13.0
4
- from keras.models import load_model # version matching your TensorFlow
5
  import cv2
6
  import json
7
 
@@ -32,28 +32,36 @@ def analyse(img, plant_type):
32
  y_pred = dnn_model.predict(process_img)
33
  y_pred = y_pred[0]
34
 
35
- # Identify predictions
36
- p_id = plant_label_disease[plant_type.lower()][0]
37
- for disease in plant_label_disease[plant_type.lower()]:
38
- if y_pred[disease] > y_pred[p_id]:
39
- p_id = disease
 
40
 
41
- overall_predicted_id = np.argmax(y_pred)
 
42
  overall_predicted_name = label_disease[str(overall_predicted_id)]
43
- overall_predicted_acc = y_pred[overall_predicted_id]
44
 
45
- plant_predicted_id = p_id
46
  plant_predicted_name = label_disease[str(plant_predicted_id)]
47
- plant_predicted_acc = y_pred[plant_predicted_id]
 
 
 
 
48
 
49
  # Return results as a JSON object
50
  result = {
51
- "plant_predicted_id": int(plant_predicted_id),
52
- "plant_predicted_name": plant_predicted_name,
53
- "plant_predicted_accuracy": float(plant_predicted_acc),
54
- "overall_predicted_id": int(overall_predicted_id),
55
- "overall_predicted_name": overall_predicted_name,
56
- "overall_predicted_accuracy": float(overall_predicted_acc),
 
 
57
  }
58
 
59
  return result
 
1
  import numpy as np
2
  import gradio as gr
3
  import tensorflow as tf # version 2.13.0
4
+ from keras.models import load_model
5
  import cv2
6
  import json
7
 
 
32
  y_pred = dnn_model.predict(process_img)
33
  y_pred = y_pred[0]
34
 
35
+ # Identify plant-specific predictions
36
+ plant_label_ids = plant_label_disease[plant_type.lower()]
37
+ plant_predicted_id = plant_label_ids[0]
38
+ for disease in plant_label_ids:
39
+ if y_pred[disease] > y_pred[plant_predicted_id]:
40
+ plant_predicted_id = disease
41
 
42
+ # Determine overall prediction
43
+ overall_predicted_id = int(np.argmax(y_pred))
44
  overall_predicted_name = label_disease[str(overall_predicted_id)]
45
+ overall_predicted_confidence = float(y_pred[overall_predicted_id])
46
 
47
+ # Determine plant-specific prediction
48
  plant_predicted_name = label_disease[str(plant_predicted_id)]
49
+ plant_predicted_confidence = float(y_pred[plant_predicted_id])
50
+
51
+ # Determine health status
52
+ is_plant_specific_healthy = "healthy" in plant_predicted_name.lower()
53
+ is_overall_healthy = "healthy" in overall_predicted_name.lower()
54
 
55
  # Return results as a JSON object
56
  result = {
57
+ "plant_specific_prediction_id": plant_predicted_id,
58
+ "plant_specific_prediction_name": plant_predicted_name,
59
+ "plant_specific_confidence": plant_predicted_confidence,
60
+ "is_plant_specific_healthy": is_plant_specific_healthy,
61
+ "overall_prediction_id": overall_predicted_id,
62
+ "overall_prediction_name": overall_predicted_name,
63
+ "overall_confidence": overall_predicted_confidence,
64
+ "is_overall_healthy": is_overall_healthy
65
  }
66
 
67
  return result