Yaswanth56 commited on
Commit
2c8e46e
·
verified ·
1 Parent(s): 3c175e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -10
app.py CHANGED
@@ -44,8 +44,8 @@ model = YOLO('./data/best.pt').to(device)
44
  if device == "cuda":
45
  model.half()
46
 
47
- # Add function to generate the PDF report with images and data
48
- def generate_pdf_report(summary: str, screenshots: List[str], pdf_path: str):
49
  c = canvas.Canvas(pdf_path, pagesize=letter)
50
  width, height = letter
51
 
@@ -58,13 +58,28 @@ def generate_pdf_report(summary: str, screenshots: List[str], pdf_path: str):
58
  c.drawString(72, height - 100, "Summary:")
59
  c.drawString(72, height - 120, summary)
60
 
61
- # Add Screenshots
62
- c.drawString(72, height - 160, "Incident Screenshots:")
63
  y_position = height - 180
 
 
 
 
 
 
 
64
  for screenshot in screenshots[:5]: # Limit to the top 5 images
65
  c.drawImage(screenshot, 72, y_position, width=150, height=100)
66
  y_position -= 120
67
 
 
 
 
 
 
 
 
 
68
  c.save()
69
 
70
  def zip_all_outputs(report_path: str, video_path: str, chart_path: str, map_path: str) -> str:
@@ -154,14 +169,16 @@ def update_metrics(detections: List[Dict[str, Any]]) -> Dict[str, Any]:
154
  "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
155
  }
156
 
157
- def generate_line_chart() -> Optional[str]:
158
- if not detected_counts:
159
  return None
160
  plt.figure(figsize=(4, 2))
161
- plt.plot(detected_counts[-50:], marker='o', color='#FF8C00')
 
 
162
  plt.title("Detections Over Time")
163
  plt.xlabel("Frame")
164
- plt.ylabel("Count")
165
  plt.grid(True)
166
  plt.tight_layout()
167
  chart_path = os.path.join(OUTPUT_DIR, f"chart_{datetime.now().strftime('%Y%m%d_%H%M%S')}.png")
@@ -311,12 +328,12 @@ def process_video(video, resize_width=4000, resize_height=3000, frame_skip=5):
311
  log_entries.append(f"Output video: {output_frames} frames, {output_fps:.2f} FPS, {output_duration:.2f} seconds")
312
 
313
  # Generate chart and map
314
- chart_path = generate_line_chart()
315
  map_path = generate_map(gps_coordinates[-5:], all_detections)
316
 
317
  # Generate the report
318
  pdf_path = f"{OUTPUT_DIR}/drone_analysis_report_{datetime.now().strftime('%Y%m%d_%H%M%S')}.pdf"
319
- generate_pdf_report("Drone analysis completed. Top 5 detections included.", detected_issues, pdf_path)
320
 
321
  log_entries.append(f"Processing completed in {total_time:.2f} seconds")
322
 
 
44
  if device == "cuda":
45
  model.half()
46
 
47
+ # Function to generate the PDF report with images and data
48
+ def generate_pdf_report(summary: str, screenshots: List[str], log_results: List[str], chart_path: str, map_path: str, pdf_path: str):
49
  c = canvas.Canvas(pdf_path, pagesize=letter)
50
  width, height = letter
51
 
 
58
  c.drawString(72, height - 100, "Summary:")
59
  c.drawString(72, height - 120, summary)
60
 
61
+ # Add Logs for Top 5 Images
62
+ c.drawString(72, height - 160, "Log Results for Top 5 Images:")
63
  y_position = height - 180
64
+ for log in log_results[:5]: # Display top 5 logs
65
+ c.drawString(72, y_position, log)
66
+ y_position -= 15
67
+
68
+ # Add Screenshots (Top 5 Images)
69
+ c.drawString(72, y_position - 20, "Incident Screenshots:")
70
+ y_position -= 40
71
  for screenshot in screenshots[:5]: # Limit to the top 5 images
72
  c.drawImage(screenshot, 72, y_position, width=150, height=100)
73
  y_position -= 120
74
 
75
+ # Add Chart Image
76
+ c.drawString(72, y_position - 20, "Detection Trend Chart:")
77
+ c.drawImage(chart_path, 72, y_position - 100, width=400, height=300)
78
+
79
+ # Add Map Image
80
+ c.drawString(72, y_position - 140, "Issue Locations Map:")
81
+ c.drawImage(map_path, 72, y_position - 240, width=400, height=300)
82
+
83
  c.save()
84
 
85
  def zip_all_outputs(report_path: str, video_path: str, chart_path: str, map_path: str) -> str:
 
169
  "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
170
  }
171
 
172
+ def generate_line_chart(detections: List[Dict[str, Any]]) -> Optional[str]:
173
+ if not detections:
174
  return None
175
  plt.figure(figsize=(4, 2))
176
+ detection_times = [det["frame"] for det in detections]
177
+ detection_counts = [det["conf"] for det in detections]
178
+ plt.plot(detection_times, detection_counts, marker='o', color='#FF8C00')
179
  plt.title("Detections Over Time")
180
  plt.xlabel("Frame")
181
+ plt.ylabel("Confidence")
182
  plt.grid(True)
183
  plt.tight_layout()
184
  chart_path = os.path.join(OUTPUT_DIR, f"chart_{datetime.now().strftime('%Y%m%d_%H%M%S')}.png")
 
328
  log_entries.append(f"Output video: {output_frames} frames, {output_fps:.2f} FPS, {output_duration:.2f} seconds")
329
 
330
  # Generate chart and map
331
+ chart_path = generate_line_chart(all_detections)
332
  map_path = generate_map(gps_coordinates[-5:], all_detections)
333
 
334
  # Generate the report
335
  pdf_path = f"{OUTPUT_DIR}/drone_analysis_report_{datetime.now().strftime('%Y%m%d_%H%M%S')}.pdf"
336
+ generate_pdf_report("Drone analysis completed. Top 5 detections included.", detected_issues, log_entries, chart_path, map_path, pdf_path)
337
 
338
  log_entries.append(f"Processing completed in {total_time:.2f} seconds")
339