Yaswanth56 commited on
Commit
961bd3b
·
verified ·
1 Parent(s): 7be3c23

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -64,8 +64,8 @@ if device == "cpu": # Optional check, not strictly needed but can help to ensur
64
  model.float() # Ensure model is running on the CPU
65
  print(f"Model classes: {model.names}")
66
 
67
- # Generate PDF report
68
- def generate_pdf_report(log_entries, detected_issues, chart_path, map_path, metrics):
69
  pdf = FPDF()
70
  pdf.set_auto_page_break(auto=True, margin=15)
71
  pdf.add_page()
@@ -92,6 +92,13 @@ def generate_pdf_report(log_entries, detected_issues, chart_path, map_path, metr
92
  pdf.multi_cell(0, 10, txt=json.dumps(metrics, indent=2))
93
  pdf.ln(5)
94
 
 
 
 
 
 
 
 
95
  # Add Chart Image
96
  if chart_path:
97
  pdf.cell(200, 10, txt="Detection Trend Chart:", ln=True)
@@ -207,6 +214,8 @@ def process_video(video, resize_width=4000, resize_height=3000, frame_skip=5):
207
  "metrics": {}
208
  }
209
 
 
 
210
  while True:
211
  ret, frame = cap.read()
212
  if not ret:
@@ -262,6 +271,8 @@ def process_video(video, resize_width=4000, resize_height=3000, frame_skip=5):
262
  if detection_frame_count % SAVE_IMAGE_INTERVAL == 0:
263
  captured_frame_path = os.path.join(CAPTURED_FRAMES_DIR, f"detected_{frame_count:06d}.jpg")
264
  if cv2.imwrite(captured_frame_path, annotated_frame):
 
 
265
  if write_geotag(captured_frame_path, gps_coord):
266
  detected_issues.append(captured_frame_path)
267
  data_lake_submission["images"].append({
@@ -357,7 +368,7 @@ def process_video(video, resize_width=4000, resize_height=3000, frame_skip=5):
357
  logs_zip = zip_directory(FLIGHT_LOG_DIR, os.path.join(OUTPUT_DIR, "flight_logs.zip"))
358
 
359
  # Generate PDF report
360
- pdf_path = generate_pdf_report(log_entries, detected_issues, chart_path, map_path, last_metrics)
361
 
362
  return (
363
  output_path,
 
64
  model.float() # Ensure model is running on the CPU
65
  print(f"Model classes: {model.names}")
66
 
67
+ # Generate PDF report with Top 5 Images
68
+ def generate_pdf_report(log_entries, detected_issues, chart_path, map_path, metrics, top_images):
69
  pdf = FPDF()
70
  pdf.set_auto_page_break(auto=True, margin=15)
71
  pdf.add_page()
 
92
  pdf.multi_cell(0, 10, txt=json.dumps(metrics, indent=2))
93
  pdf.ln(5)
94
 
95
+ # Add Top 5 Images
96
+ pdf.cell(200, 10, txt="Top 5 Detected Images:", ln=True)
97
+ for image_path in top_images:
98
+ if os.path.exists(image_path):
99
+ pdf.image(image_path, x=10, y=pdf.get_y(), w=180)
100
+ pdf.ln(60) # Space out the images
101
+
102
  # Add Chart Image
103
  if chart_path:
104
  pdf.cell(200, 10, txt="Detection Trend Chart:", ln=True)
 
214
  "metrics": {}
215
  }
216
 
217
+ top_images = [] # Track top 5 images
218
+
219
  while True:
220
  ret, frame = cap.read()
221
  if not ret:
 
271
  if detection_frame_count % SAVE_IMAGE_INTERVAL == 0:
272
  captured_frame_path = os.path.join(CAPTURED_FRAMES_DIR, f"detected_{frame_count:06d}.jpg")
273
  if cv2.imwrite(captured_frame_path, annotated_frame):
274
+ if len(top_images) < 5: # Keep track of only top 5 images
275
+ top_images.append(captured_frame_path)
276
  if write_geotag(captured_frame_path, gps_coord):
277
  detected_issues.append(captured_frame_path)
278
  data_lake_submission["images"].append({
 
368
  logs_zip = zip_directory(FLIGHT_LOG_DIR, os.path.join(OUTPUT_DIR, "flight_logs.zip"))
369
 
370
  # Generate PDF report
371
+ pdf_path = generate_pdf_report(log_entries, detected_issues, chart_path, map_path, last_metrics, top_images)
372
 
373
  return (
374
  output_path,