Spaces:
Running
Running
Update report_structure.py
Browse files- report_structure.py +8 -13
report_structure.py
CHANGED
@@ -56,7 +56,6 @@ def generate_report(research_output: str, filename="research_report.pdf"):
|
|
56 |
toc_h1_style = ParagraphStyle(
|
57 |
'TOC_H1_Style',
|
58 |
parent=styles['Heading2'],
|
59 |
-
|
60 |
)
|
61 |
|
62 |
# --- Title Page ---
|
@@ -71,8 +70,8 @@ def generate_report(research_output: str, filename="research_report.pdf"):
|
|
71 |
# --- Table of Contents (Placeholder) ---
|
72 |
story.append(Paragraph("Table of Contents", h1_style))
|
73 |
toc_entries = extract_toc(research_output)
|
74 |
-
for level,
|
75 |
-
story.append(Paragraph(f"{
|
76 |
story.append(PageBreak())
|
77 |
|
78 |
# --- Main Content ---
|
@@ -84,11 +83,9 @@ def generate_report(research_output: str, filename="research_report.pdf"):
|
|
84 |
story.append(Paragraph(para.strip(), normal_style))
|
85 |
story.append(Spacer(1, 12))
|
86 |
|
87 |
-
doc.build(story, onFirstPage=add_page_number, onLaterPages=add_page_number)
|
88 |
return research_output
|
89 |
|
90 |
-
|
91 |
-
|
92 |
def extract_title(text):
|
93 |
"""Extracts the title from the research output (simple heuristic)."""
|
94 |
lines = text.split("\n")
|
@@ -103,12 +100,11 @@ def extract_toc(text):
|
|
103 |
lines = text.split("\n")
|
104 |
for i,line in enumerate(lines):
|
105 |
if line.startswith("# ") and line.count(".")<=3:
|
106 |
-
toc.append((1, line[2:].strip()))
|
107 |
-
elif line.startswith("## ")and line.count(".")<=3:
|
108 |
-
toc.append((2, line[3:].strip()))
|
109 |
return toc
|
110 |
|
111 |
-
|
112 |
def split_into_sections(text):
|
113 |
"""Splits the research output into sections based on headings."""
|
114 |
sections = {}
|
@@ -128,10 +124,9 @@ def split_into_sections(text):
|
|
128 |
|
129 |
return sections
|
130 |
|
131 |
-
|
132 |
def add_page_number(canvas, doc):
|
133 |
"""Adds page numbers to the footer."""
|
134 |
canvas.saveState()
|
135 |
canvas.setFont('Times-Roman', 9)
|
136 |
-
canvas.drawString(letter[0] - 72, 0.75 * 72, "Page %d" % doc.page)
|
137 |
-
canvas.restoreState()
|
|
|
56 |
toc_h1_style = ParagraphStyle(
|
57 |
'TOC_H1_Style',
|
58 |
parent=styles['Heading2'],
|
|
|
59 |
)
|
60 |
|
61 |
# --- Title Page ---
|
|
|
70 |
# --- Table of Contents (Placeholder) ---
|
71 |
story.append(Paragraph("Table of Contents", h1_style))
|
72 |
toc_entries = extract_toc(research_output)
|
73 |
+
for level, title_text in toc_entries:
|
74 |
+
story.append(Paragraph(f"{title_text}", styles['Normal']))
|
75 |
story.append(PageBreak())
|
76 |
|
77 |
# --- Main Content ---
|
|
|
83 |
story.append(Paragraph(para.strip(), normal_style))
|
84 |
story.append(Spacer(1, 12))
|
85 |
|
86 |
+
doc.build(story, onFirstPage=add_page_number, onLaterPages=add_page_number)
|
87 |
return research_output
|
88 |
|
|
|
|
|
89 |
def extract_title(text):
|
90 |
"""Extracts the title from the research output (simple heuristic)."""
|
91 |
lines = text.split("\n")
|
|
|
100 |
lines = text.split("\n")
|
101 |
for i,line in enumerate(lines):
|
102 |
if line.startswith("# ") and line.count(".")<=3:
|
103 |
+
toc.append((1, line[2:].strip()))
|
104 |
+
elif line.startswith("## ") and line.count(".")<=3:
|
105 |
+
toc.append((2, line[3:].strip()))
|
106 |
return toc
|
107 |
|
|
|
108 |
def split_into_sections(text):
|
109 |
"""Splits the research output into sections based on headings."""
|
110 |
sections = {}
|
|
|
124 |
|
125 |
return sections
|
126 |
|
|
|
127 |
def add_page_number(canvas, doc):
|
128 |
"""Adds page numbers to the footer."""
|
129 |
canvas.saveState()
|
130 |
canvas.setFont('Times-Roman', 9)
|
131 |
+
canvas.drawString(letter[0] - 72, 0.75 * 72, "Page %d" % doc.page)
|
132 |
+
canvas.restoreState()
|