Guiyom commited on
Commit
e764258
·
verified ·
1 Parent(s): 6475772

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -5
app.py CHANGED
@@ -903,7 +903,8 @@ class ReportGenerator:
903
  html_content = html_content.replace("<h2>Conclusion</h2>", "<div class='page-break'></div><h2>Conclusion</h2>")
904
  html_content = html_content.replace("<h2>References</h2>", "<div class='page-break'></div><h2>References</h2>")
905
  html_content = html_content.replace("<h2>Surprise-Me Extension Report</h2>", "<div class='page-break'></div><h2>Surprise-Me Extension Report</h2>")
906
-
 
907
  date_str = datetime.now().strftime("%Y-%m-%d")
908
  header = ""
909
  if metadata:
@@ -911,13 +912,18 @@ class ReportGenerator:
911
  <p>Author: {metadata.get('User name', 'N/A')}</p>
912
  <p>Date: {metadata.get('Date', date_str)}</p>
913
  <hr/>"""
914
-
915
- logging.info(f"ReportGenerator: HTML report generated successfully:\n{html_content}")
916
- return html_content
 
 
 
 
 
917
 
918
  def generate_report_pdf(self, solution_content: str, metadata: dict = None) -> bytes:
919
  # Generate the full HTML report (including text, focus placeholders, and mermaid visuals as iframes)
920
- html_report = self.generate_report_html(solution_content, metadata)
921
 
922
  # Parse the HTML
923
  soup = BeautifulSoup(html_report, "html.parser")
@@ -1002,6 +1008,10 @@ class ReportGenerator:
1002
  return cleaned_string
1003
  cleaned_string = remove_img_tags(final_html)
1004
  logging.info(f"ReportGenerator: Final HTML for PDF conversion:\n{cleaned_string}")
 
 
 
 
1005
 
1006
  # Generate the final PDF from final_html using xhtml2pdf (A4 layout)
1007
  pdf_buffer = io.BytesIO()
 
903
  html_content = html_content.replace("<h2>Conclusion</h2>", "<div class='page-break'></div><h2>Conclusion</h2>")
904
  html_content = html_content.replace("<h2>References</h2>", "<div class='page-break'></div><h2>References</h2>")
905
  html_content = html_content.replace("<h2>Surprise-Me Extension Report</h2>", "<div class='page-break'></div><h2>Surprise-Me Extension Report</h2>")
906
+
907
+ # Add header
908
  date_str = datetime.now().strftime("%Y-%m-%d")
909
  header = ""
910
  if metadata:
 
912
  <p>Author: {metadata.get('User name', 'N/A')}</p>
913
  <p>Date: {metadata.get('Date', date_str)}</p>
914
  <hr/>"""
915
+ soup = BeautifulSoup(html_content, "html.parser")
916
+ body_tag = soup.body
917
+ if body_tag:
918
+ body_tag.insert(0, BeautifulSoup(header, "html.parser"))
919
+ updated_html = str(soup)
920
+
921
+ logging.info(f"ReportGenerator: HTML report generated successfully:\n{updated_html}")
922
+ return updated_html
923
 
924
  def generate_report_pdf(self, solution_content: str, metadata: dict = None) -> bytes:
925
  # Generate the full HTML report (including text, focus placeholders, and mermaid visuals as iframes)
926
+ html_report = self.generate_report_html(solution_content)
927
 
928
  # Parse the HTML
929
  soup = BeautifulSoup(html_report, "html.parser")
 
1008
  return cleaned_string
1009
  cleaned_string = remove_img_tags(final_html)
1010
  logging.info(f"ReportGenerator: Final HTML for PDF conversion:\n{cleaned_string}")
1011
+
1012
+ #Post-processing tests
1013
+ final_html = final_html.replace("<h1>Abstract</h1>","<h1>Abst<br>ract</h1>")
1014
+
1015
 
1016
  # Generate the final PDF from final_html using xhtml2pdf (A4 layout)
1017
  pdf_buffer = io.BytesIO()