Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -185,7 +185,7 @@ def generate_report(
|
|
185 |
r"\usepackage{amsmath}",
|
186 |
r"\usepackage{caption}",
|
187 |
r"\usepackage{pdfpages}",
|
188 |
-
r"\usepackage{times}",
|
189 |
r"\begin{document}",
|
190 |
r"\title{NHAI Drone Survey Analysis Report}",
|
191 |
r"\author{Nagasurendra, Data Analyst}",
|
@@ -199,7 +199,7 @@ def generate_report(
|
|
199 |
r"\item \textbf{Highway Section}: Km 100 to Km 150",
|
200 |
r"\item \textbf{State}: Telangana",
|
201 |
r"\item \textbf{Region}: South",
|
202 |
-
rf"\item \textbf{{Survey Date}}: {datetime.now().strftime('%Y-%m-%d')}",
|
203 |
r"\item \textbf{Drone Service Provider}: ABC Drone Services Pvt. Ltd.",
|
204 |
r"\item \textbf{Technology Service Provider}: XYZ AI Analytics Ltd.",
|
205 |
rf"\item \textbf{{Work Order Reference}}: Data Lake WO-{datetime.now().strftime('%Y-%m-%d')}-XYZ",
|
@@ -364,16 +364,90 @@ def generate_report(
|
|
364 |
# Writing LaTeX file
|
365 |
with open(tex_path, 'w') as f:
|
366 |
f.write("\n".join(report_content))
|
367 |
-
log_entries.append(f"LaTeX
|
368 |
|
369 |
# Compiling LaTeX to PDF using latexmk
|
370 |
import subprocess
|
371 |
-
subprocess.run(
|
372 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
373 |
return report_path
|
374 |
except Exception as e:
|
375 |
log_entries.append(f"Error: Failed to generate report: {str(e)}")
|
376 |
return ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
377 |
def process_video(video, resize_width=4000, resize_height=3000, frame_skip=5):
|
378 |
global frame_count, last_metrics, detected_counts, detected_issues, gps_coordinates, log_entries
|
379 |
frame_count = 0
|
|
|
185 |
r"\usepackage{amsmath}",
|
186 |
r"\usepackage{caption}",
|
187 |
r"\usepackage{pdfpages}",
|
188 |
+
r"\usepackage{times}",
|
189 |
r"\begin{document}",
|
190 |
r"\title{NHAI Drone Survey Analysis Report}",
|
191 |
r"\author{Nagasurendra, Data Analyst}",
|
|
|
199 |
r"\item \textbf{Highway Section}: Km 100 to Km 150",
|
200 |
r"\item \textbf{State}: Telangana",
|
201 |
r"\item \textbf{Region}: South",
|
202 |
+
rf"\item \textbf{{Survey Date}}: {datetime.now().strftime('%Y-%m-%d')}",
|
203 |
r"\item \textbf{Drone Service Provider}: ABC Drone Services Pvt. Ltd.",
|
204 |
r"\item \textbf{Technology Service Provider}: XYZ AI Analytics Ltd.",
|
205 |
rf"\item \textbf{{Work Order Reference}}: Data Lake WO-{datetime.now().strftime('%Y-%m-%d')}-XYZ",
|
|
|
364 |
# Writing LaTeX file
|
365 |
with open(tex_path, 'w') as f:
|
366 |
f.write("\n".join(report_content))
|
367 |
+
log_entries.append(f"LaTeX file saved: {tex_path}")
|
368 |
|
369 |
# Compiling LaTeX to PDF using latexmk
|
370 |
import subprocess
|
371 |
+
result = subprocess.run(
|
372 |
+
["latexmk", "-pdf", "-interaction=nonstopmode", tex_path],
|
373 |
+
cwd=OUTPUT_DIR,
|
374 |
+
capture_output=True,
|
375 |
+
text=True
|
376 |
+
)
|
377 |
+
if result.returncode == 0:
|
378 |
+
log_entries.append(f"PDF report generated: {report_path}")
|
379 |
+
if os.path.exists(report_path):
|
380 |
+
log_entries.append(f"Confirmed report file exists: {report_path}")
|
381 |
+
else:
|
382 |
+
log_entries.append(f"Error: PDF report not found at {report_path}")
|
383 |
+
return ""
|
384 |
+
else:
|
385 |
+
log_entries.append(f"Error: LaTeX compilation failed: {result.stderr}")
|
386 |
+
return ""
|
387 |
return report_path
|
388 |
except Exception as e:
|
389 |
log_entries.append(f"Error: Failed to generate report: {str(e)}")
|
390 |
return ""
|
391 |
+
|
392 |
+
def zip_all_outputs(report_path: str, video_path: str, chart_path: str, map_path: str) -> str:
|
393 |
+
zip_path = os.path.join(OUTPUT_DIR, f"drone_analysis_outputs_{datetime.now().strftime('%Y%m%d_%H%M%S')}.zip")
|
394 |
+
try:
|
395 |
+
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
396 |
+
# Add report file
|
397 |
+
if report_path and os.path.exists(report_path):
|
398 |
+
zipf.write(report_path, os.path.basename(report_path))
|
399 |
+
log_entries.append(f"Added report to ZIP: {report_path}")
|
400 |
+
else:
|
401 |
+
log_entries.append(f"Warning: Report file not found for ZIP: {report_path}")
|
402 |
+
|
403 |
+
# Add video file
|
404 |
+
if video_path and os.path.exists(video_path):
|
405 |
+
zipf.write(video_path, os.path.join("outputs", os.path.basename(video_path)))
|
406 |
+
log_entries.append(f"Added video to ZIP: {video_path}")
|
407 |
+
else:
|
408 |
+
log_entries.append(f"Warning: Video file not found for ZIP: {video_path}")
|
409 |
+
|
410 |
+
# Add chart file
|
411 |
+
if chart_path and os.path.exists(chart_path):
|
412 |
+
zipf.write(chart_path, os.path.join("outputs", os.path.basename(chart_path)))
|
413 |
+
log_entries.append(f"Added chart to ZIP: {chart_path}")
|
414 |
+
else:
|
415 |
+
log_entries.append(f"Warning: Chart file not found for ZIP: {chart_path}")
|
416 |
+
|
417 |
+
# Add map file
|
418 |
+
if map_path and os.path.exists(map_path):
|
419 |
+
zipf.write(map_path, os.path.join("outputs", os.path.basename(map_path)))
|
420 |
+
log_entries.append(f"Added map to ZIP: {map_path}")
|
421 |
+
else:
|
422 |
+
log_entries.append(f"Warning: Map file not found for ZIP: {map_path}")
|
423 |
+
|
424 |
+
# Add detected issue images
|
425 |
+
for file in detected_issues:
|
426 |
+
if os.path.exists(file):
|
427 |
+
zipf.write(file, os.path.join("captured_frames", os.path.basename(file)))
|
428 |
+
log_entries.append(f"Added image to ZIP: {file}")
|
429 |
+
else:
|
430 |
+
log_entries.append(f"Warning: Image file not found for ZIP: {file}")
|
431 |
+
|
432 |
+
# Add flight logs
|
433 |
+
for root, _, files in os.walk(FLIGHT_LOG_DIR):
|
434 |
+
for file in files:
|
435 |
+
file_path = os.path.join(root, file)
|
436 |
+
if os.path.exists(file_path):
|
437 |
+
zipf.write(file_path, os.path.join("flight_logs", file))
|
438 |
+
log_entries.append(f"Added flight log to ZIP: {file_path}")
|
439 |
+
else:
|
440 |
+
log_entries.append(f"Warning: Flight log not found for ZIP: {file_path}")
|
441 |
+
|
442 |
+
log_entries.append(f"Created ZIP: {zip_path}")
|
443 |
+
if os.path.exists(zip_path):
|
444 |
+
log_entries.append(f"Confirmed ZIP file exists: {zip_path}")
|
445 |
+
else:
|
446 |
+
log_entries.append(f"Error: ZIP file not created: {zip_path}")
|
447 |
+
return zip_path
|
448 |
+
except Exception as e:
|
449 |
+
log_entries.append(f"Error: Failed to create ZIP: {str(e)}")
|
450 |
+
return ""
|
451 |
def process_video(video, resize_width=4000, resize_height=3000, frame_skip=5):
|
452 |
global frame_count, last_metrics, detected_counts, detected_issues, gps_coordinates, log_entries
|
453 |
frame_count = 0
|