anilkumar5590 commited on
Commit
f30ed89
·
verified ·
1 Parent(s): 0da19c9

Update backendapi.py

Browse files
Files changed (1) hide show
  1. backendapi.py +17 -8
backendapi.py CHANGED
@@ -161,15 +161,24 @@ def predict():
161
 
162
  # Generate explanation using Gemini AI
163
  explanation = generate_explanation(predicted_class)
164
-
165
- # Store the result in the in-memory dictionary
166
- prediction_id = str(time.time()) # Unique ID for the request
167
- prediction_results[prediction_id] = {
168
- "predicted_class": predicted_class,
169
- "conservation_status": conservation_status,
170
- "confidence_level": confidence_level,
171
- "explanation": explanation
172
  }
 
 
 
 
 
 
 
 
 
173
  print(f"Prediction ID: {prediction_id}, Result: {prediction_results[prediction_id]}")
174
  return jsonify({"prediction_id": prediction_id}), 200
175
 
 
161
 
162
  # Generate explanation using Gemini AI
163
  explanation = generate_explanation(predicted_class)
164
+ prediction_results = {}
165
+ if confidence_level<=30:
166
+ prediction_id = str(time.time()) # Unique ID for the request
167
+ prediction_results[prediction_id] = {
168
+ "predicted_class": "---",
169
+ "conservation_status": "---",
170
+ "confidence_level": "---",
171
+ "explanation": "Sorry! This image doesn’t seem to match any animals I was trained on. I’m doing my best with the knowledge I have. Please try a different image – ideally of a single, clear animal."
172
  }
173
+ else:
174
+ # Store the result in the in-memory dictionary
175
+ prediction_id = str(time.time()) # Unique ID for the request
176
+ prediction_results[prediction_id] = {
177
+ "predicted_class": predicted_class,
178
+ "conservation_status": conservation_status,
179
+ "confidence_level": confidence_level,
180
+ "explanation": explanation
181
+ }
182
  print(f"Prediction ID: {prediction_id}, Result: {prediction_results[prediction_id]}")
183
  return jsonify({"prediction_id": prediction_id}), 200
184