Spaces:
Running
Running
Update app.py
Browse files
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
|
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 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
40 |
|
41 |
-
|
|
|
42 |
overall_predicted_name = label_disease[str(overall_predicted_id)]
|
43 |
-
|
44 |
|
45 |
-
|
46 |
plant_predicted_name = label_disease[str(plant_predicted_id)]
|
47 |
-
|
|
|
|
|
|
|
|
|
48 |
|
49 |
# Return results as a JSON object
|
50 |
result = {
|
51 |
-
"
|
52 |
-
"
|
53 |
-
"
|
54 |
-
"
|
55 |
-
"
|
56 |
-
"
|
|
|
|
|
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
|