Spaces:
Sleeping
Sleeping
import os | |
from reportlab.lib.pagesizes import letter | |
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer | |
from reportlab.lib.styles import getSampleStyleSheet | |
def export_report_to_pdf(query, summary, citations, structures, funding_data, regulation_data, filename="output.pdf"): | |
"""Export research report to PDF.""" | |
filepath = os.path.join(os.getcwd(), filename) | |
doc = SimpleDocTemplate(filepath, pagesize=letter) | |
styles = getSampleStyleSheet() | |
story = [] | |
# Title | |
story.append(Paragraph(f"GENESIS-AI Research Report", styles["Title"])) | |
story.append(Spacer(1, 12)) | |
# Query | |
story.append(Paragraph(f"<b>Query:</b> {query}", styles["Normal"])) | |
story.append(Spacer(1, 12)) | |
# Summary | |
story.append(Paragraph("<b>Summary:</b>", styles["Heading2"])) | |
story.append(Paragraph(summary, styles["Normal"])) | |
story.append(Spacer(1, 12)) | |
# Citations | |
if citations: | |
story.append(Paragraph("<b>Citations:</b>", styles["Heading2"])) | |
for c in citations: | |
story.append(Paragraph(f"{c.get('type', '')}: {c.get('url', '')}", styles["Normal"])) | |
story.append(Spacer(1, 12)) | |
# Structures | |
if structures: | |
story.append(Paragraph("<b>Structures:</b>", styles["Heading2"])) | |
for s in structures: | |
story.append(Paragraph(str(s), styles["Normal"])) | |
story.append(Spacer(1, 12)) | |
# Funding | |
if funding_data: | |
story.append(Paragraph("<b>Funding Data:</b>", styles["Heading2"])) | |
for f in funding_data: | |
story.append(Paragraph(str(f), styles["Normal"])) | |
story.append(Spacer(1, 12)) | |
# Regulation | |
if regulation_data: | |
story.append(Paragraph("<b>Regulatory Info:</b>", styles["Heading2"])) | |
for r in regulation_data: | |
story.append(Paragraph(str(r), styles["Normal"])) | |
story.append(Spacer(1, 12)) | |
doc.build(story) | |
return filepath | |