Update utils.py
Browse files
utils.py
CHANGED
|
@@ -32,7 +32,7 @@ def generate_pdf_report(summary, screenshots, output_path):
|
|
| 32 |
"""
|
| 33 |
Generate a PDF report using LaTeX with summary and embedded screenshots.
|
| 34 |
"""
|
| 35 |
-
#
|
| 36 |
latex_content = r"""
|
| 37 |
\documentclass[a4paper,12pt]{article}
|
| 38 |
\usepackage[utf8]{inputenc}
|
|
@@ -43,7 +43,6 @@ def generate_pdf_report(summary, screenshots, output_path):
|
|
| 43 |
\usepackage{caption}
|
| 44 |
\usepackage{subcaption}
|
| 45 |
|
| 46 |
-
% Preamble for document setup
|
| 47 |
\title{Road Safety Analysis Report}
|
| 48 |
\author{Generated by Road Safety AI}
|
| 49 |
\date{\today}
|
|
@@ -54,8 +53,8 @@ def generate_pdf_report(summary, screenshots, output_path):
|
|
| 54 |
|
| 55 |
\section*{Analysis Summary}
|
| 56 |
\begin{itemize}
|
| 57 |
-
% Insert summary lines dynamically
|
| 58 |
"""
|
|
|
|
| 59 |
for line in summary.split('\n'):
|
| 60 |
if line.strip():
|
| 61 |
latex_content += f"\item {line.strip()}\n"
|
|
@@ -66,15 +65,16 @@ def generate_pdf_report(summary, screenshots, output_path):
|
|
| 66 |
\section*{Incident Screenshots}
|
| 67 |
\begin{figure}[h]
|
| 68 |
\centering
|
| 69 |
-
"""
|
| 70 |
|
| 71 |
-
|
|
|
|
| 72 |
latex_content += f"""
|
| 73 |
-
\begin{subfigure}[t]{0.45
|
| 74 |
-
\includegraphics[width
|
| 75 |
-
\caption{Incident Frame {i+1}}
|
| 76 |
-
\end{subfigure}
|
| 77 |
-
|
| 78 |
if (i + 1) % 2 == 0 and i < len(screenshots) - 1:
|
| 79 |
latex_content += r" \hfill "
|
| 80 |
|
|
@@ -83,7 +83,7 @@ def generate_pdf_report(summary, screenshots, output_path):
|
|
| 83 |
\end{figure}
|
| 84 |
|
| 85 |
\end{document}
|
| 86 |
-
"""
|
| 87 |
|
| 88 |
# Write LaTeX to a file
|
| 89 |
tex_file = "templates/report.tex"
|
|
|
|
| 32 |
"""
|
| 33 |
Generate a PDF report using LaTeX with summary and embedded screenshots.
|
| 34 |
"""
|
| 35 |
+
# Define LaTeX content as a raw string to handle backslashes correctly
|
| 36 |
latex_content = r"""
|
| 37 |
\documentclass[a4paper,12pt]{article}
|
| 38 |
\usepackage[utf8]{inputenc}
|
|
|
|
| 43 |
\usepackage{caption}
|
| 44 |
\usepackage{subcaption}
|
| 45 |
|
|
|
|
| 46 |
\title{Road Safety Analysis Report}
|
| 47 |
\author{Generated by Road Safety AI}
|
| 48 |
\date{\today}
|
|
|
|
| 53 |
|
| 54 |
\section*{Analysis Summary}
|
| 55 |
\begin{itemize}
|
|
|
|
| 56 |
"""
|
| 57 |
+
# Add summary lines
|
| 58 |
for line in summary.split('\n'):
|
| 59 |
if line.strip():
|
| 60 |
latex_content += f"\item {line.strip()}\n"
|
|
|
|
| 65 |
\section*{Incident Screenshots}
|
| 66 |
\begin{figure}[h]
|
| 67 |
\centering
|
| 68 |
+
"""
|
| 69 |
|
| 70 |
+
# Add up to 5 screenshots
|
| 71 |
+
for i, screenshot in enumerate(screenshots[:5]):
|
| 72 |
latex_content += f"""
|
| 73 |
+
\begin{{subfigure}}[t]{{0.45\\textwidth}}
|
| 74 |
+
\includegraphics[width=\\textwidth]{{{screenshot}}}
|
| 75 |
+
\caption{{Incident Frame {i+1}}}
|
| 76 |
+
\end{{subfigure}}
|
| 77 |
+
"""
|
| 78 |
if (i + 1) % 2 == 0 and i < len(screenshots) - 1:
|
| 79 |
latex_content += r" \hfill "
|
| 80 |
|
|
|
|
| 83 |
\end{figure}
|
| 84 |
|
| 85 |
\end{document}
|
| 86 |
+
"""
|
| 87 |
|
| 88 |
# Write LaTeX to a file
|
| 89 |
tex_file = "templates/report.tex"
|