Akshanshsensei/PDF-Constrained-Conversational-Agent
1
1"""2Script to generate the sample evaluation PDF for the PDF-Constrained Agent.3Run with: python create_sample_pdf.py4"""5from reportlab.lib.pagesizes import A46from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle7from reportlab.lib.units import cm8from reportlab.lib import colors9from reportlab.platypus import (10 SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle, PageBreak11)12from reportlab.lib.enums import TA_CENTER, TA_JUSTIFY13 14OUTPUT_PATH = "sample.pdf"15 16doc = SimpleDocTemplate(17 OUTPUT_PATH,18 pagesize=A4,19 rightMargin=2*cm,20 leftMargin=2*cm,21 topMargin=2*cm,22 bottomMargin=2*cm23)24 25styles = getSampleStyleSheet()26title_style = ParagraphStyle(27 "CustomTitle", parent=styles["Title"],28 fontSize=22, spaceAfter=12, textColor=colors.HexColor("#1a1a2e")29)30h1_style = ParagraphStyle(31 "H1", parent=styles["Heading1"],32 fontSize=16, spaceAfter=8, textColor=colors.HexColor("#16213e")33)34h2_style = ParagraphStyle(35 "H2", parent=styles["Heading2"],36 fontSize=13, spaceAfter=6, textColor=colors.HexColor("#0f3460")37)38body_style = ParagraphStyle(39 "Body", parent=styles["BodyText"],40 fontSize=11, leading=16, spaceAfter=8, alignment=TA_JUSTIFY41)42caption_style = ParagraphStyle(43 "Caption", parent=styles["Normal"],44 fontSize=9, textColor=colors.grey, spaceAfter=12, alignment=TA_CENTER45)46 47story = []48 49# ─── PAGE 1: Cover & Executive Summary ─────────────────────────────────────50story.append(Spacer(1, 1.5*cm))51story.append(Paragraph("Global Climate Change Report 2024", title_style))52story.append(Paragraph("An Analysis of Causes, Impacts, and Mitigation Strategies", styles["Heading2"]))53story.append(Spacer(1, 0.5*cm))54story.append(Paragraph(55 "Published by: The International Climate Research Consortium (ICRC) | Edition: Fifth Annual Report",56 caption_style57))58story.append(Spacer(1, 0.5*cm))59 60story.append(Paragraph("Executive Summary", h1_style))61story.append(Paragraph(62 "Global average surface temperatures have risen by approximately 1.1 degrees Celsius above "63 "pre-industrial levels as of 2024. This warming is unequivocally driven by human activities, "64 "primarily the combustion of fossil fuels such as coal, oil, and natural gas, which releases "65 "carbon dioxide (CO2) and other greenhouse gases into the atmosphere. The concentration of "66 "atmospheric CO2 has reached 421 parts per million (ppm), the highest level in over 800,000 years.",67 body_style68))69story.append(Paragraph(70 "The consequences are far-reaching: rising sea levels threatening coastal communities, "71 "increased frequency and intensity of extreme weather events, disruption of ecosystems, "72 "and threats to global food security. Without immediate and sustained action to reduce "73 "greenhouse gas emissions, global temperatures are projected to rise by 2.5 to 4.0 degrees "74 "Celsius by the end of the century, leading to catastrophic and largely irreversible impacts.",75 body_style76))77story.append(Paragraph(78 "This report recommends a tripartite response strategy: aggressive deployment of renewable "79 "energy sources to decarbonize the power sector; implementation of carbon pricing mechanisms "80 "to drive economy-wide emissions reductions; and substantial investment in adaptation "81 "measures to protect vulnerable communities from unavoidable climate impacts.",82 body_style83))84story.append(PageBreak())85 86# ─── PAGE 2: Causes of Climate Change ─────────────────────────────────────87story.append(Paragraph("Section 1: Primary Causes of Climate Change", h1_style))88story.append(Paragraph("1.1 The Greenhouse Effect and Human Emissions", h2_style))89story.append(Paragraph(90 "The greenhouse effect is a natural process where certain gases in the Earth's atmosphere "91 "trap heat from the sun, keeping the planet warm enough to support life. The primary "92 "greenhouse gases include carbon dioxide (CO2), methane (CH4), nitrous oxide (N2O), and "93 "fluorinated gases. Human industrial activities since the mid-18th century have dramatically "94 "amplified this natural effect, leading to the current climate crisis.",95 body_style96))97story.append(Paragraph(98 "Fossil fuel combustion for electricity and heat generation accounts for the largest share "99 "of global greenhouse gas emissions at 34%. Transportation contributes 16%, while industry "100 "accounts for 24%. Agriculture, forestry, and land use change collectively contribute 22%, "101 "with methane from livestock and nitrous oxide from fertilizers being the primary drivers "102 "in this category. Buildings account for the remaining 6% of global emissions.",103 body_style104))105story.append(Paragraph("1.2 Deforestation and Land Use Change", h2_style))106story.append(Paragraph(107 "Forests serve as critical carbon sinks, absorbing approximately 2.6 billion tonnes of CO2 "108 "per year. Deforestation, primarily for agricultural expansion and logging, not only destroys "109 "this carbon storage capacity but also releases stored carbon into the atmosphere. The Amazon "110 "rainforest, often called the 'lungs of the Earth,' has lost approximately 17% of its original "111 "extent due to deforestation, a figure that climate scientists warn is approaching a dangerous "112 "tipping point beyond which the forest could transition to a savanna ecosystem.",113 body_style114))115story.append(PageBreak())116 117# ─── PAGE 3: Observed Impacts ──────────────────────────────────────────────118story.append(Paragraph("Section 2: Observed and Projected Impacts", h1_style))119story.append(Paragraph("2.1 Rising Sea Levels", h2_style))120story.append(Paragraph(121 "Global mean sea levels have risen by approximately 21 centimeters since 1900, with the rate "122 "of rise accelerating significantly in recent decades. The current rate is approximately 3.7 "123 "millimeters per year. This rise is driven by two main factors: thermal expansion of warming "124 "ocean waters (accounting for 42% of observed rise) and the melting of land-based ice sheets "125 "and glaciers (accounting for 58%). Low-lying island nations such as Tuvalu, Kiribati, and "126 "the Maldives face existential threats from rising seas and increased storm surge.",127 body_style128))129story.append(Paragraph("2.2 Extreme Weather Events", h2_style))130story.append(Paragraph(131 "Scientific evidence increasingly links climate change to the intensification of extreme "132 "weather events. The frequency of Category 4 and 5 hurricanes has increased by 25-30% since "133 "the 1980s. Heatwaves that would have occurred once every 50 years in a pre-industrial climate "134 "now occur every 10 years on average. Precipitation extremes are also intensifying: wet regions "135 "are getting wetter and dry regions are getting drier, increasing both flood and drought risks.",136 body_style137))138story.append(Paragraph("2.3 Arctic and Antarctic Ice Loss", h2_style))139story.append(Paragraph(140 "The Arctic is warming at a rate approximately four times faster than the global average, a "141 "phenomenon known as Arctic Amplification. Arctic sea ice extent has declined by approximately "142 "13% per decade since satellite records began in 1979. The Greenland Ice Sheet is losing mass "143 "at an average rate of 280 billion tonnes per year, while the Antarctic Ice Sheet loses "144 "approximately 150 billion tonnes annually. If the West Antarctic Ice Sheet were to collapse "145 "entirely, it would raise global sea levels by approximately 3.3 meters.",146 body_style147))148story.append(PageBreak())149 150# ─── PAGE 4: Mitigation & Adaptation ──────────────────────────────────────151story.append(Paragraph("Section 3: Mitigation and Adaptation Strategies", h1_style))152story.append(Paragraph("3.1 Renewable Energy Transition", h2_style))153story.append(Paragraph(154 "The rapid deployment of renewable energy is the cornerstone of climate mitigation. Solar "155 "photovoltaic (PV) and wind energy are now the cheapest sources of new electricity generation "156 "in most of the world. The cost of solar PV has fallen by 89% over the past decade, and "157 "wind power costs have dropped by 70%. Global renewable energy capacity reached 3,372 gigawatts "158 "in 2023. To limit warming to 1.5 degrees Celsius, renewable energy must supply at least 85% "159 "of global electricity by 2050, up from the current 30%.",160 body_style161))162story.append(Paragraph("3.2 Carbon Pricing", h2_style))163story.append(Paragraph(164 "Carbon pricing is widely considered the most economically efficient policy instrument for "165 "reducing greenhouse gas emissions. It works by putting a direct price on carbon emissions, "166 "incentivizing businesses and individuals to reduce their carbon footprint. There are two main "167 "forms: a carbon tax, which sets a direct price on emissions, and an emissions trading system "168 "(ETS), also known as cap-and-trade, which sets a cap on total emissions and allows entities "169 "to buy and sell allowances. As of 2024, 73 carbon pricing initiatives are in place globally, "170 "covering approximately 23% of global greenhouse gas emissions.",171 body_style172))173story.append(Paragraph("3.3 The Role of Nature-Based Solutions", h2_style))174story.append(Paragraph(175 "Nature-based solutions (NbS) — such as reforestation, wetland restoration, and sustainable "176 "agricultural practices — can contribute up to 30% of the emissions reductions needed by 2030 "177 "to meet the Paris Agreement goals. Reforestation programs in particular are gaining momentum: "178 "the Bonn Challenge, a global effort to restore 350 million hectares of degraded land by 2030, "179 "has already seen pledges covering 210 million hectares. However, scientists caution that "180 "nature-based solutions are not a substitute for deep, rapid reductions in fossil fuel emissions.",181 body_style182))183story.append(PageBreak())184 185# ─── PAGE 5: Multilingual Section & Key Statistics ─────────────────────────186story.append(Paragraph("Section 4: Global Policy Context and Key Statistics", h1_style))187story.append(Paragraph("4.1 The Paris Agreement", h2_style))188story.append(Paragraph(189 "The Paris Agreement, adopted in December 2015 under the United Nations Framework Convention "190 "on Climate Change (UNFCCC), represents the landmark international accord on climate action. "191 "Its central aim is to limit global average temperature increases to well below 2 degrees "192 "Celsius above pre-industrial levels, and to pursue efforts to limit warming to 1.5 degrees "193 "Celsius. As of 2024, 195 countries have ratified the agreement. Each country submits "194 "Nationally Determined Contributions (NDCs) outlining its climate action plans. "195 "However, a 2023 analysis found that current NDCs are collectively insufficient and would "196 "lead to warming of approximately 2.5 to 2.9 degrees Celsius by 2100.",197 body_style198))199 200story.append(Paragraph("4.2 Key Statistics at a Glance", h2_style))201table_data = [202 ["Indicator", "Value", "Year"],203 ["Global Temperature Rise", "1.1°C above pre-industrial", "2024"],204 ["Atmospheric CO2 Concentration", "421 parts per million (ppm)", "2024"],205 ["Annual Sea Level Rise Rate", "3.7 mm per year", "2023"],206 ["Renewable Energy Global Share", "30% of electricity generation", "2023"],207 ["Annual Arctic Sea Ice Loss", "13% per decade since 1979", "2024"],208 ["Countries with Carbon Pricing", "73 initiatives globally", "2024"],209 ["Cost Reduction of Solar PV", "89% decline over last decade", "2023"],210]211table = Table(table_data, colWidths=[7*cm, 7*cm, 3*cm])212table.setStyle(TableStyle([213 ("BACKGROUND", (0, 0), (-1, 0), colors.HexColor("#0f3460")),214 ("TEXTCOLOR", (0, 0), (-1, 0), colors.white),215 ("FONTNAME", (0, 0), (-1, 0), "Helvetica-Bold"),216 ("FONTSIZE", (0, 0), (-1, 0), 10),217 ("ALIGN", (0, 0), (-1, -1), "CENTER"),218 ("VALIGN", (0, 0), (-1, -1), "MIDDLE"),219 ("ROWBACKGROUNDS", (0, 1), (-1, -1), [colors.white, colors.HexColor("#f0f4f8")]),220 ("FONTSIZE", (0, 1), (-1, -1), 9),221 ("GRID", (0, 0), (-1, -1), 0.5, colors.HexColor("#cccccc")),222 ("TOPPADDING", (0, 0), (-1, -1), 6),223 ("BOTTOMPADDING", (0, 0), (-1, -1), 6),224]))225story.append(table)226story.append(Spacer(1, 0.5*cm))227 228story.append(Paragraph("4.3 Multilingual Summary (Bonus: Non-English Grounding Test)", h2_style))229story.append(Paragraph(230 "<b>Hindi (हिंदी):</b> जलवायु परिवर्तन आज के समय की सबसे बड़ी वैश्विक चुनौती है। "231 "वायुमंडल में CO2 की सांद्रता 421 ppm तक पहुँच गई है, जो पिछले 800,000 वर्षों में "232 "सबसे अधिक है। इसे नियंत्रित करने के लिए नवीकरणीय ऊर्जा को अपनाना अनिवार्य है।",233 body_style234))235story.append(Paragraph(236 "<b>French (Français):</b> Le changement climatique est la plus grande menace environnementale "237 "de notre époque. La température moyenne mondiale a augmenté de 1,1 degré Celsius depuis "238 "l'ère préindustrielle. L'Accord de Paris vise à limiter ce réchauffement à 1,5 degré Celsius.",239 body_style240))241 242doc.build(story)243print(f"Sample PDF created successfully at: {OUTPUT_PATH}")244 