Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -31,10 +31,11 @@ gps_coordinates = []
|
|
31 |
TEMP_IMAGE_PATH = "temp.jpg"
|
32 |
CAPTURED_FRAMES_DIR = "captured_frames"
|
33 |
os.makedirs(CAPTURED_FRAMES_DIR, exist_ok=True)
|
|
|
34 |
|
35 |
# Core monitor function
|
36 |
def monitor_feed():
|
37 |
-
global paused, frame_count, last_frame, last_metrics, last_timestamp, gps_coordinates
|
38 |
|
39 |
if paused and last_frame is not None:
|
40 |
frame = last_frame.copy()
|
@@ -60,8 +61,12 @@ def monitor_feed():
|
|
60 |
captured_frame_path = os.path.join(CAPTURED_FRAMES_DIR, f"crack_{frame_count}.jpg")
|
61 |
cv2.imwrite(captured_frame_path, frame)
|
62 |
last_detected_images.append(captured_frame_path)
|
63 |
-
if len(last_detected_images) >
|
64 |
-
last_detected_images.pop(0)
|
|
|
|
|
|
|
|
|
65 |
|
66 |
last_frame = frame.copy()
|
67 |
last_metrics = metrics.copy()
|
@@ -141,7 +146,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
141 |
|
142 |
with gr.Row():
|
143 |
map_output = gr.Image(label="Crack Locations Map")
|
144 |
-
captured_images = gr.Gallery(label="Detected Cracks (Last
|
145 |
|
146 |
with gr.Row():
|
147 |
pause_btn = gr.Button("鈴革笍 Pause")
|
|
|
31 |
TEMP_IMAGE_PATH = "temp.jpg"
|
32 |
CAPTURED_FRAMES_DIR = "captured_frames"
|
33 |
os.makedirs(CAPTURED_FRAMES_DIR, exist_ok=True)
|
34 |
+
MAX_GALLERY_IMAGES = 100 # Increased to store up to 100 images
|
35 |
|
36 |
# Core monitor function
|
37 |
def monitor_feed():
|
38 |
+
global paused, frame_count, last_frame, last_metrics, last_timestamp, gps_coordinates, last_detected_images
|
39 |
|
40 |
if paused and last_frame is not None:
|
41 |
frame = last_frame.copy()
|
|
|
61 |
captured_frame_path = os.path.join(CAPTURED_FRAMES_DIR, f"crack_{frame_count}.jpg")
|
62 |
cv2.imwrite(captured_frame_path, frame)
|
63 |
last_detected_images.append(captured_frame_path)
|
64 |
+
if len(last_detected_images) > MAX_GALLERY_IMAGES:
|
65 |
+
oldest_image = last_detected_images.pop(0)
|
66 |
+
try:
|
67 |
+
os.remove(oldest_image)
|
68 |
+
except:
|
69 |
+
pass # Ignore if file can't be deleted
|
70 |
|
71 |
last_frame = frame.copy()
|
72 |
last_metrics = metrics.copy()
|
|
|
146 |
|
147 |
with gr.Row():
|
148 |
map_output = gr.Image(label="Crack Locations Map")
|
149 |
+
captured_images = gr.Gallery(label=f"Detected Cracks (Last {MAX_GALLERY_IMAGES})", elem_id="gallery", columns=5, object_fit="contain", height="auto")
|
150 |
|
151 |
with gr.Row():
|
152 |
pause_btn = gr.Button("鈴革笍 Pause")
|