Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -670,8 +670,12 @@ HTML_TEMPLATE = """
|
|
| 670 |
`;
|
| 671 |
|
| 672 |
if (numObstacles && numObstacles !== '0') {
|
| 673 |
-
|
| 674 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 675 |
}
|
| 676 |
|
| 677 |
successMessage += `</div>`;
|
|
@@ -1002,15 +1006,15 @@ OBSTACLES_HTML_TEMPLATE = """
|
|
| 1002 |
function updateStatus() {
|
| 1003 |
const existingCount = Object.values(obstaclesData).filter(o => o && o.exists).length;
|
| 1004 |
const statusEl = document.getElementById('status');
|
| 1005 |
-
statusEl.textContent = `Displaying ${existingCount}/8 obstacles`;
|
| 1006 |
|
| 1007 |
if (existingCount === 0) {
|
| 1008 |
statusEl.style.backgroundColor = '#fff3cd';
|
| 1009 |
statusEl.style.color = '#856404';
|
| 1010 |
-
statusEl.textContent = 'No obstacles detected yet. Upload images with NUM_OBSTACLES parameter (1-8).';
|
| 1011 |
} else {
|
| 1012 |
statusEl.style.backgroundColor = '#d4edda';
|
| 1013 |
statusEl.style.color = '#155724';
|
|
|
|
| 1014 |
}
|
| 1015 |
}
|
| 1016 |
|
|
@@ -1102,8 +1106,16 @@ def image_predict():
|
|
| 1102 |
class_id, detection_result = process_file(file_path, signal, task_type, filename)
|
| 1103 |
|
| 1104 |
# Handle NUM_OBSTACLES parameter for obstacle display
|
| 1105 |
-
|
|
|
|
|
|
|
| 1106 |
save_obstacle_image(detection_result, int(num_obstacles))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1107 |
|
| 1108 |
if detection_result is None:
|
| 1109 |
return jsonify({'error': 'Failed to process image'}), 500
|
|
|
|
| 670 |
`;
|
| 671 |
|
| 672 |
if (numObstacles && numObstacles !== '0') {
|
| 673 |
+
if (predictedId === '-1') {
|
| 674 |
+
successMessage += `<br><span style="color: #ffc107;">⚠️ Obstacle ${numObstacles} not saved - No valid detection (ID: -1)</span>`;
|
| 675 |
+
} else {
|
| 676 |
+
successMessage += `<br><span style="color: #28a745;">✓ Saved as Obstacle ${numObstacles}</span>`;
|
| 677 |
+
successMessage += `<br><a href="/obstacles" target="_blank" style="color: #007bff; text-decoration: underline;">View Obstacles Display</a>`;
|
| 678 |
+
}
|
| 679 |
}
|
| 680 |
|
| 681 |
successMessage += `</div>`;
|
|
|
|
| 1006 |
function updateStatus() {
|
| 1007 |
const existingCount = Object.values(obstaclesData).filter(o => o && o.exists).length;
|
| 1008 |
const statusEl = document.getElementById('status');
|
|
|
|
| 1009 |
|
| 1010 |
if (existingCount === 0) {
|
| 1011 |
statusEl.style.backgroundColor = '#fff3cd';
|
| 1012 |
statusEl.style.color = '#856404';
|
| 1013 |
+
statusEl.textContent = 'No obstacles detected yet. Upload images with NUM_OBSTACLES parameter (1-8) and valid detections (ID ≠ -1).';
|
| 1014 |
} else {
|
| 1015 |
statusEl.style.backgroundColor = '#d4edda';
|
| 1016 |
statusEl.style.color = '#155724';
|
| 1017 |
+
statusEl.textContent = `Displaying ${existingCount}/8 obstacles with valid detections`;
|
| 1018 |
}
|
| 1019 |
}
|
| 1020 |
|
|
|
|
| 1106 |
class_id, detection_result = process_file(file_path, signal, task_type, filename)
|
| 1107 |
|
| 1108 |
# Handle NUM_OBSTACLES parameter for obstacle display
|
| 1109 |
+
# Only save if detection is valid (image_id != '-1')
|
| 1110 |
+
if (num_obstacles and num_obstacles.isdigit() and 1 <= int(num_obstacles) <= 8
|
| 1111 |
+
and detection_result and detection_result.get('image_id') != '-1'):
|
| 1112 |
save_obstacle_image(detection_result, int(num_obstacles))
|
| 1113 |
+
print(f"Obstacle {num_obstacles} saved with valid detection (ID: {detection_result.get('image_id')})")
|
| 1114 |
+
elif (num_obstacles and num_obstacles.isdigit() and 1 <= int(num_obstacles) <= 8
|
| 1115 |
+
and detection_result and detection_result.get('image_id') == '-1'):
|
| 1116 |
+
print(f"Obstacle {num_obstacles} NOT saved - invalid detection (ID: -1)")
|
| 1117 |
+
elif num_obstacles and num_obstacles.isdigit() and 1 <= int(num_obstacles) <= 8:
|
| 1118 |
+
print(f"Obstacle {num_obstacles} NOT saved - no detection result")
|
| 1119 |
|
| 1120 |
if detection_result is None:
|
| 1121 |
return jsonify({'error': 'Failed to process image'}), 500
|