Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -164,21 +164,21 @@ def run_temporal_analysis(stream_id, frames_3d_copy, prob_max, prob_mean, prob_m
|
|
| 164 |
|
| 165 |
try:
|
| 166 |
ensemble_probs = model_svm.predict_proba(combined)[0]
|
| 167 |
-
final_idx =
|
| 168 |
confidence = float(ensemble_probs[final_idx] * 100)
|
| 169 |
severity = classes[final_idx]
|
| 170 |
-
except
|
| 171 |
-
final_idx = min(int(np.argmax(prob_max)), 2)
|
| 172 |
-
confidence = float(np.max(prob_max)) * 100
|
| 173 |
severity = classes[final_idx]
|
| 174 |
|
| 175 |
state["severity"] = severity.capitalize()
|
| 176 |
state["confidence"] = round(confidence, 1)
|
|
|
|
| 177 |
state["rcnn"] = round(float(np.max(prob_3d)) * 100, 1)
|
| 178 |
|
| 179 |
-
#
|
| 180 |
-
|
| 181 |
-
if confidence > 75 and yolo_max_conf > 50.0:
|
| 182 |
state["final_decision"] = True
|
| 183 |
state["label"] = f"Incident Logged: {severity.capitalize()}"
|
| 184 |
threading.Thread(target=process_accident_async, args=(stream_id, raw_frame, location, confidence, severity)).start()
|
|
@@ -186,7 +186,7 @@ def run_temporal_analysis(stream_id, frames_3d_copy, prob_max, prob_mean, prob_m
|
|
| 186 |
state["label"] = f"Analyzing... ({severity.capitalize()})"
|
| 187 |
|
| 188 |
except Exception as e:
|
| 189 |
-
print(f"AI Error
|
| 190 |
finally:
|
| 191 |
if state: state["is_analyzing"] = False
|
| 192 |
|
|
|
|
| 164 |
|
| 165 |
try:
|
| 166 |
ensemble_probs = model_svm.predict_proba(combined)[0]
|
| 167 |
+
final_idx = model_svm.predict(combined)[0]
|
| 168 |
confidence = float(ensemble_probs[final_idx] * 100)
|
| 169 |
severity = classes[final_idx]
|
| 170 |
+
except:
|
| 171 |
+
final_idx = min(int(np.argmax(prob_max)), 2)
|
| 172 |
+
confidence = float(np.max(prob_max)) * 100
|
| 173 |
severity = classes[final_idx]
|
| 174 |
|
| 175 |
state["severity"] = severity.capitalize()
|
| 176 |
state["confidence"] = round(confidence, 1)
|
| 177 |
+
state["cnn"] = round(yolo_max_conf, 1)
|
| 178 |
state["rcnn"] = round(float(np.max(prob_3d)) * 100, 1)
|
| 179 |
|
| 180 |
+
# FIX: Restored threshold back to 85 from 75 to completely eliminate false positives on noisy live feeds
|
| 181 |
+
if confidence > 85:
|
|
|
|
| 182 |
state["final_decision"] = True
|
| 183 |
state["label"] = f"Incident Logged: {severity.capitalize()}"
|
| 184 |
threading.Thread(target=process_accident_async, args=(stream_id, raw_frame, location, confidence, severity)).start()
|
|
|
|
| 186 |
state["label"] = f"Analyzing... ({severity.capitalize()})"
|
| 187 |
|
| 188 |
except Exception as e:
|
| 189 |
+
print(f"AI Error: {e}", flush=True)
|
| 190 |
finally:
|
| 191 |
if state: state["is_analyzing"] = False
|
| 192 |
|