lokesh341 commited on
Commit
3c35ee6
·
verified ·
1 Parent(s): ace9fda

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -40
app.py CHANGED
@@ -43,6 +43,7 @@ try:
43
  from services.plantation.missing_patch_check import process_missing_patches
44
  except ImportError as e:
45
  print(f"Failed to import service modules: {str(e)}")
 
46
  exit(1)
47
 
48
  # Configure logging
@@ -79,15 +80,17 @@ os.makedirs(OUTPUT_DIR, exist_ok=True)
79
  def initialize_video(video_file: Optional[Any] = None) -> str:
80
  global video_loaded, log_entries
81
  release_video()
82
- video_path = DEFAULT_VIDEO_PATH
 
 
 
 
 
 
 
83
 
84
- if video_file is not None:
85
- video_path = video_file.name
86
- log_entries.append(f"Using uploaded video: {video_path}")
87
- logging.info(f"Using uploaded video: {video_path}")
88
-
89
  try:
90
- preload_video()
91
  video_loaded = True
92
  status = f"Successfully loaded video: {video_path}"
93
  log_entries.append(status)
@@ -133,35 +136,50 @@ def set_active_service(
133
  logging.info("No service category enabled.")
134
  return None, "No Service Category Enabled"
135
 
136
- def generate_line_chart() -> Optional[str]:
137
  if not crack_counts:
138
  return None
139
- fig, ax = plt.subplots(figsize=(4, 2))
140
- ax.plot(crack_counts[-50:], marker='o', color='#4682B4')
141
- ax.set_title("Cracks/Holes Over Time")
142
- ax.set_xlabel("Frame")
143
- ax.set_ylabel("Count")
144
- ax.grid(True)
145
- fig.tight_layout()
146
- chart_path = "chart_temp.png"
147
- fig.savefig(chart_path)
148
- plt.close(fig)
149
- return chart_path
150
-
151
- def generate_pie_chart() -> Optional[str]:
152
- if not crack_severity_all:
153
- return None
154
- fig, ax = plt.subplots(figsize=(4, 2))
155
- count = Counter(crack_severity_all[-200:])
156
- labels, sizes = zip(*count.items())
157
- colors = ['#FF6347', '#FFA500', '#32CD32', '#800080']
158
- ax.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=140, colors=colors[:len(labels)])
159
- ax.axis('equal')
160
- fig.tight_layout()
161
- pie_path = "pie_temp.png"
162
- fig.savefig(pie_path)
163
- plt.close(fig)
164
- return pie_path
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
 
166
  def monitor_feed() -> Tuple[
167
  Optional[np.ndarray],
@@ -170,13 +188,19 @@ def monitor_feed() -> Tuple[
170
  List[str],
171
  List[str],
172
  Optional[str],
173
- Optional[str]
174
- ]:
175
- global paused, frame_count, last_frame, last_metrics, last_timestamp
176
- global gps_coordinates, last_detected_cracks, last_detected_holes, video_loaded
 
 
 
 
 
 
177
 
178
  if not video_loaded:
179
- log_entries.append("Cannot start streaming: Video not loaded successfully.")
180
  logging.error("Video not loaded successfully.")
181
  return (
182
  None,
@@ -241,6 +265,7 @@ def monitor_feed() -> Tuple[
241
  all_detected_items.extend(generic_dets)
242
 
243
  # Apply shadow detection
 
244
  shadow_issue = detect_shadow_coverage(TEMP_IMAGE_PATH)
245
 
246
  # Apply thermal processing if frame is grayscale
@@ -373,7 +398,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="green"))
373
 
374
  with gr.Row():
375
  with gr.Column(scale=3):
376
- video_input = gr.File(label="Upload Video File (e.g., sample.mp4)", file_types=["video"])
377
  load_button = gr.Button("Load Video", variant="primary")
378
  with gr.Column(scale=1):
379
  video_status = gr.Textbox(
 
43
  from services.plantation.missing_patch_check import process_missing_patches
44
  except ImportError as e:
45
  print(f"Failed to import service modules: {str(e)}")
46
+ logging.error(f"Import error: {str(e)}")
47
  exit(1)
48
 
49
  # Configure logging
 
80
  def initialize_video(video_file: Optional[Any] = None) -> str:
81
  global video_loaded, log_entries
82
  release_video()
83
+ video_path = DEFAULT_VIDEO_PATH if video_file is None else video_file.name
84
+
85
+ if not os.path.exists(video_path):
86
+ status = f"Error: Video file '{video_path}' not found."
87
+ log_entries.append(status)
88
+ logging.error(status)
89
+ video_loaded = False
90
+ return status
91
 
 
 
 
 
 
92
  try:
93
+ preload_video(video_path)
94
  video_loaded = True
95
  status = f"Successfully loaded video: {video_path}"
96
  log_entries.append(status)
 
136
  logging.info("No service category enabled.")
137
  return None, "No Service Category Enabled"
138
 
139
+ def generate_line_chart():
140
  if not crack_counts:
141
  return None
142
+ ```chartjs
143
+ {
144
+ "type": "line",
145
+ "data": {
146
+ "labels": [i for i in range(len(crack_counts[-50:]))],
147
+ "datasets": [{
148
+ "label": crack_counts[-50:],
149
+ "data": crack_counts[-50:],
150
+ "borderColor": "#4682B4",
151
+ "backgroundColor": "#4682B4",
152
+ "fill": false,
153
+ "pointBackgroundColor": "#3CB371",
154
+ "pointRadius": 5
155
+ }]
156
+ },
157
+ "options": {
158
+ "responsive": false,
159
+ "scales": {
160
+ "x": {
161
+ "title": {
162
+ "display": true,
163
+ "text": "Frame"
164
+ }
165
+ },
166
+ "y": {
167
+ "title": {
168
+ "display": true,
169
+ "text": "Count of Cracks/Holes"
170
+ }
171
+ }
172
+ },
173
+ "title": {
174
+ "display": true,
175
+ "text": "Cracks/Holes Over Time"
176
+ }
177
+ }
178
+ }
179
+ ```
180
+
181
+ def generate_map(gps_coordinates: List[List[float]], items: List[Dict]]) -> Optional[str]:
182
+ return generate_map(gps_coordinates, items)
183
 
184
  def monitor_feed() -> Tuple[
185
  Optional[np.ndarray],
 
188
  List[str],
189
  List[str],
190
  Optional[str],
191
+ global
192
+ paused,
193
+ frame_count,
194
+ last_frame,
195
+ last_metrics,
196
+ last_timestamp,
197
+ gps_coordinates,
198
+ last_detected_cracks,
199
+ last_detected_holes,
200
+ video_loaded
201
 
202
  if not video_loaded:
203
+ log_entries.append(("Cannot start streaming: Video not loaded successfully.")
204
  logging.error("Video not loaded successfully.")
205
  return (
206
  None,
 
265
  all_detected_items.extend(generic_dets)
266
 
267
  # Apply shadow detection
268
+ cv2.imwrite(TEMP_IMAGE_PATH, frame)
269
  shadow_issue = detect_shadow_coverage(TEMP_IMAGE_PATH)
270
 
271
  # Apply thermal processing if frame is grayscale
 
398
 
399
  with gr.Row():
400
  with gr.Column(scale=3):
401
+ video_input = gr.File(label="Upload Video File (e.g., sample.mp4)", file_types=[".mp4", ".avi"])
402
  load_button = gr.Button("Load Video", variant="primary")
403
  with gr.Column(scale=1):
404
  video_status = gr.Textbox(