Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -40,7 +40,12 @@ def monitor_feed():
|
|
40 |
frame = last_frame.copy()
|
41 |
metrics = last_metrics.copy()
|
42 |
else:
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
44 |
detected_boxes = detect_cracks(frame)
|
45 |
frame = overlay_boxes(frame, detected_boxes)
|
46 |
cv2.imwrite(TEMP_IMAGE_PATH, frame, [int(cv2.IMWRITE_JPEG_QUALITY), 95])
|
@@ -48,7 +53,7 @@ def monitor_feed():
|
|
48 |
|
49 |
frame_count += 1
|
50 |
last_timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
51 |
-
gps_coord = simulate_gps_coordinates(frame_count)
|
52 |
gps_coordinates.append(gps_coord)
|
53 |
|
54 |
if detected_boxes:
|
@@ -89,6 +94,8 @@ def monitor_feed():
|
|
89 |
|
90 |
# Line chart
|
91 |
def generate_line_chart():
|
|
|
|
|
92 |
fig, ax = plt.subplots(figsize=(4, 2))
|
93 |
ax.plot(crack_counts[-50:], marker='o')
|
94 |
ax.set_title("Cracks Over Time")
|
@@ -162,7 +169,10 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
162 |
def streaming_loop():
|
163 |
while True:
|
164 |
frame, metrics, logs, chart, pie, captured, map_path = monitor_feed()
|
165 |
-
|
|
|
|
|
|
|
166 |
time.sleep(frame_rate)
|
167 |
|
168 |
app.load(streaming_loop, outputs=[video_output, metrics_output, logs_output, chart_output, pie_output, captured_images, map_output])
|
|
|
40 |
frame = last_frame.copy()
|
41 |
metrics = last_metrics.copy()
|
42 |
else:
|
43 |
+
try:
|
44 |
+
frame = get_next_video_frame()
|
45 |
+
except RuntimeError as e:
|
46 |
+
log_entries.append(f"Error: {str(e)}")
|
47 |
+
return None, last_metrics, "\n".join(log_entries[-10:]), None, None, last_detected_images, None
|
48 |
+
|
49 |
detected_boxes = detect_cracks(frame)
|
50 |
frame = overlay_boxes(frame, detected_boxes)
|
51 |
cv2.imwrite(TEMP_IMAGE_PATH, frame, [int(cv2.IMWRITE_JPEG_QUALITY), 95])
|
|
|
53 |
|
54 |
frame_count += 1
|
55 |
last_timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
56 |
+
gps_coord = simulate_gps_coordinates(frame_count)
|
57 |
gps_coordinates.append(gps_coord)
|
58 |
|
59 |
if detected_boxes:
|
|
|
94 |
|
95 |
# Line chart
|
96 |
def generate_line_chart():
|
97 |
+
if not crack_counts:
|
98 |
+
return None
|
99 |
fig, ax = plt.subplots(figsize=(4, 2))
|
100 |
ax.plot(crack_counts[-50:], marker='o')
|
101 |
ax.set_title("Cracks Over Time")
|
|
|
169 |
def streaming_loop():
|
170 |
while True:
|
171 |
frame, metrics, logs, chart, pie, captured, map_path = monitor_feed()
|
172 |
+
if frame is None:
|
173 |
+
yield None, str(metrics), logs, chart, pie, captured, map_path
|
174 |
+
else:
|
175 |
+
yield frame, str(metrics), logs, chart, pie, captured, map_path
|
176 |
time.sleep(frame_rate)
|
177 |
|
178 |
app.load(streaming_loop, outputs=[video_output, metrics_output, logs_output, chart_output, pie_output, captured_images, map_output])
|