Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,6 @@ import os
|
|
8 |
import logging
|
9 |
import requests
|
10 |
from io import BytesIO
|
11 |
-
import json
|
12 |
|
13 |
# Setup logging
|
14 |
logging.basicConfig(level=logging.INFO)
|
@@ -79,42 +78,37 @@ def predict_from_image_url(image_url):
|
|
79 |
|
80 |
# Interpret the result
|
81 |
if predicted_class == 0:
|
82 |
-
|
83 |
-
"result": "The photo
|
84 |
"probabilities": {
|
85 |
"Fall Army Worm": f"{probabilities[0]*100:.2f}%",
|
86 |
"Phosphorus Deficiency": f"{probabilities[1]*100:.2f}%",
|
87 |
"Bacterial Leaf Blight": f"{probabilities[2]*100:.2f}%"
|
88 |
}
|
89 |
-
}
|
90 |
-
return json_output
|
91 |
elif predicted_class == 1:
|
92 |
-
|
93 |
-
"result": "The photo shows symptoms of Phosphorus
|
94 |
"probabilities": {
|
95 |
"Fall Army Worm": f"{probabilities[0]*100:.2f}%",
|
96 |
"Phosphorus Deficiency": f"{probabilities[1]*100:.2f}%",
|
97 |
"Bacterial Leaf Blight": f"{probabilities[2]*100:.2f}%"
|
98 |
}
|
99 |
-
}
|
100 |
-
return json_output
|
101 |
elif predicted_class == 2:
|
102 |
-
|
103 |
"result": "The photo shows symptoms of Bacterial Leaf Blight with Problem ID 203.",
|
104 |
"probabilities": {
|
105 |
"Fall Army Worm": f"{probabilities[0]*100:.2f}%",
|
106 |
"Phosphorus Deficiency": f"{probabilities[1]*100:.2f}%",
|
107 |
"Bacterial Leaf Blight": f"{probabilities[2]*100:.2f}%"
|
108 |
}
|
109 |
-
}
|
110 |
-
return json_output
|
111 |
else:
|
112 |
-
|
113 |
-
return json_output
|
114 |
|
115 |
except Exception as e:
|
116 |
-
|
117 |
-
return json_output
|
118 |
|
119 |
# Gradio interface
|
120 |
demo = gr.Interface(
|
|
|
8 |
import logging
|
9 |
import requests
|
10 |
from io import BytesIO
|
|
|
11 |
|
12 |
# Setup logging
|
13 |
logging.basicConfig(level=logging.INFO)
|
|
|
78 |
|
79 |
# Interpret the result
|
80 |
if predicted_class == 0:
|
81 |
+
return {
|
82 |
+
"result": "The photo is of Fall Army Worm with problem ID 126.",
|
83 |
"probabilities": {
|
84 |
"Fall Army Worm": f"{probabilities[0]*100:.2f}%",
|
85 |
"Phosphorus Deficiency": f"{probabilities[1]*100:.2f}%",
|
86 |
"Bacterial Leaf Blight": f"{probabilities[2]*100:.2f}%"
|
87 |
}
|
88 |
+
}
|
|
|
89 |
elif predicted_class == 1:
|
90 |
+
return {
|
91 |
+
"result": "The photo shows symptoms of Phosphorus Deficiency with Problem ID 142.",
|
92 |
"probabilities": {
|
93 |
"Fall Army Worm": f"{probabilities[0]*100:.2f}%",
|
94 |
"Phosphorus Deficiency": f"{probabilities[1]*100:.2f}%",
|
95 |
"Bacterial Leaf Blight": f"{probabilities[2]*100:.2f}%"
|
96 |
}
|
97 |
+
}
|
|
|
98 |
elif predicted_class == 2:
|
99 |
+
return {
|
100 |
"result": "The photo shows symptoms of Bacterial Leaf Blight with Problem ID 203.",
|
101 |
"probabilities": {
|
102 |
"Fall Army Worm": f"{probabilities[0]*100:.2f}%",
|
103 |
"Phosphorus Deficiency": f"{probabilities[1]*100:.2f}%",
|
104 |
"Bacterial Leaf Blight": f"{probabilities[2]*100:.2f}%"
|
105 |
}
|
106 |
+
}
|
|
|
107 |
else:
|
108 |
+
return {"error": "Unexpected class prediction."}
|
|
|
109 |
|
110 |
except Exception as e:
|
111 |
+
return {"error": str(e)}
|
|
|
112 |
|
113 |
# Gradio interface
|
114 |
demo = gr.Interface(
|