Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -905,9 +905,23 @@ class ReportGenerator:
|
|
| 905 |
def generate_report_pdf(self, solution_content: str, metadata: dict = None) -> bytes:
|
| 906 |
# Generate the full HTML report (including text, focus placeholders, and mermaid visuals as iframes)
|
| 907 |
html_report = self.generate_report_html(solution_content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 908 |
|
| 909 |
# Parse the HTML
|
| 910 |
-
soup = BeautifulSoup(html_report, "html.parser")
|
| 911 |
logging.info(f"ReportGenerator: soup report generated:\n{soup}")
|
| 912 |
|
| 913 |
# Find all mermaid visual iframes (assumed to have class "mermaid-frame")
|
|
@@ -989,29 +1003,14 @@ class ReportGenerator:
|
|
| 989 |
return cleaned_string
|
| 990 |
cleaned_string = remove_img_tags(final_html)
|
| 991 |
|
| 992 |
-
|
| 993 |
-
date_str = datetime.now().strftime("%Y-%m-%d")
|
| 994 |
-
header = ""
|
| 995 |
-
if metadata:
|
| 996 |
-
header = f"""
|
| 997 |
-
<h1>Search Query: {metadata.get('Query name', 'N/A')}</h1>
|
| 998 |
-
<p>Author: {metadata.get('User name', 'N/A')}</p>
|
| 999 |
-
<p>Date: {metadata.get('Date', date_str)}</p>
|
| 1000 |
-
<hr/>"""
|
| 1001 |
-
soup = BeautifulSoup(cleaned_string, "html.parser")
|
| 1002 |
-
body_tag = soup.body
|
| 1003 |
-
if body_tag:
|
| 1004 |
-
body_tag.insert(0, BeautifulSoup(header, "html.parser"))
|
| 1005 |
-
updated_html = str(soup)
|
| 1006 |
-
|
| 1007 |
-
logging.info(f"ReportGenerator: Final HTML for PDF conversion:\n{updated_html}")
|
| 1008 |
|
| 1009 |
#Post-processing tests
|
| 1010 |
-
|
| 1011 |
|
| 1012 |
# Generate the final PDF from final_html using xhtml2pdf (A4 layout)
|
| 1013 |
pdf_buffer = io.BytesIO()
|
| 1014 |
-
pisa_status = pisa.CreatePDF(
|
| 1015 |
link_callback=lambda uri, rel: uri,
|
| 1016 |
default_css="""
|
| 1017 |
@page {
|
|
|
|
| 905 |
def generate_report_pdf(self, solution_content: str, metadata: dict = None) -> bytes:
|
| 906 |
# Generate the full HTML report (including text, focus placeholders, and mermaid visuals as iframes)
|
| 907 |
html_report = self.generate_report_html(solution_content)
|
| 908 |
+
|
| 909 |
+
# Add header
|
| 910 |
+
date_str = datetime.now().strftime("%Y-%m-%d")
|
| 911 |
+
header = ""
|
| 912 |
+
if metadata:
|
| 913 |
+
header = f"""
|
| 914 |
+
<h1>Search Query: {metadata.get('Query name', 'N/A')}</h1>
|
| 915 |
+
<p>Author: {metadata.get('User name', 'N/A')}</p>
|
| 916 |
+
<p>Date: {metadata.get('Date', date_str)}</p>
|
| 917 |
+
<hr/>"""
|
| 918 |
+
soup = BeautifulSoup(html_report, "html.parser")
|
| 919 |
+
body_tag = soup.body
|
| 920 |
+
if body_tag:
|
| 921 |
+
body_tag.insert(0, BeautifulSoup(header, "html.parser"))
|
| 922 |
+
updated_html = str(soup)
|
| 923 |
|
| 924 |
# Parse the HTML
|
|
|
|
| 925 |
logging.info(f"ReportGenerator: soup report generated:\n{soup}")
|
| 926 |
|
| 927 |
# Find all mermaid visual iframes (assumed to have class "mermaid-frame")
|
|
|
|
| 1003 |
return cleaned_string
|
| 1004 |
cleaned_string = remove_img_tags(final_html)
|
| 1005 |
|
| 1006 |
+
logging.info(f"ReportGenerator: Final HTML for PDF conversion:\n{cleaned_string}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1007 |
|
| 1008 |
#Post-processing tests
|
| 1009 |
+
final_html = final_html.replace("<h1>Abstract</h1>","<h1>Abs ;lkj sdf;tract</h1>")
|
| 1010 |
|
| 1011 |
# Generate the final PDF from final_html using xhtml2pdf (A4 layout)
|
| 1012 |
pdf_buffer = io.BytesIO()
|
| 1013 |
+
pisa_status = pisa.CreatePDF(final_html, dest=pdf_buffer,
|
| 1014 |
link_callback=lambda uri, rel: uri,
|
| 1015 |
default_css="""
|
| 1016 |
@page {
|