rairo commited on
Commit
2d7fff3
·
verified ·
1 Parent(s): b07357c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -10
app.py CHANGED
@@ -141,18 +141,17 @@ def generate_financial_report(model, aggregated_data, start_date, end_date, stat
141
  st.info(f"Preparing to generate {statement_type} with pre-aggregated data...")
142
 
143
  # This is the final, simplified, high-level prompt with no special characters.
144
- prompt = f"""
145
- You are an expert financial analyst. Your task is to generate a professional Income Statement in Markdown format using the pre-aggregated JSON data provided below.
146
 
147
- JSON Data:
148
  {json.dumps(aggregated_data, indent=2)}
149
 
150
- Instructions:
151
- Your response must be a complete financial report in Markdown.
152
  The main title of the report is "Income Statement".
153
  The reporting period is from {start_date.strftime('%d %B %Y')} to {end_date.strftime('%d %B %Y')}.
154
  The currency is South African Rand (ZAR).
155
  The report must contain sections for Revenue, Operating Expenses, and Net Income or Loss. Each of these sections must be a clear table.
 
156
  The report must also include a "Key Highlights" section with bullet points and a final "Summary" paragraph.
157
  Use the provided JSON data for all financial figures.
158
  For the Net Income or Loss table, if the net position is negative, display the amount in parentheses.
@@ -192,7 +191,7 @@ def create_pdf_report(report_text):
192
 
193
  for element in soup.find_all(True):
194
  if element.name in ['h1', 'h2', 'h3']:
195
- level = int(element.name[1])
196
  font_size = {1: 16, 2: 14, 3: 12}.get(level)
197
  pdf.set_font('helvetica', 'B', font_size)
198
  pdf.multi_cell(0, 10, element.get_text().strip())
@@ -212,7 +211,8 @@ def create_pdf_report(report_text):
212
  pdf.ln(2)
213
  for li in element.find_all('li'):
214
  pdf.set_font('helvetica', '', 11)
215
- pdf.multi_cell(0, 5, f" • {li.get_text().strip()}")
 
216
  pdf.ln(1)
217
  pdf.ln(4)
218
  elif element.name == 'table':
@@ -233,8 +233,8 @@ def create_pdf_report(report_text):
233
  if is_total_row:
234
  pdf.set_font('helvetica', 'B', 10)
235
 
236
- pdf.cell(col_widths[0], 7, row[0], border=1)
237
- pdf.cell(col_widths[1], 7, row[1], border=1, align='R')
238
  pdf.ln()
239
 
240
  if is_total_row:
@@ -243,7 +243,6 @@ def create_pdf_report(report_text):
243
 
244
  st.info("Content added to PDF. Outputting PDF to buffer...")
245
 
246
- # --- CRITICAL FIX FOR PDF GENERATION ---
247
  pdf_output = pdf.output()
248
 
249
  st.success("PDF report generated successfully.")
 
141
  st.info(f"Preparing to generate {statement_type} with pre-aggregated data...")
142
 
143
  # This is the final, simplified, high-level prompt with no special characters.
144
+ prompt = f"""You are an expert financial analyst. Your task is to generate a professional Income Statement in Markdown format using the pre-aggregated JSON data provided below.
 
145
 
146
+ Here is the financial data:
147
  {json.dumps(aggregated_data, indent=2)}
148
 
149
+ Your instructions for the report are:
 
150
  The main title of the report is "Income Statement".
151
  The reporting period is from {start_date.strftime('%d %B %Y')} to {end_date.strftime('%d %B %Y')}.
152
  The currency is South African Rand (ZAR).
153
  The report must contain sections for Revenue, Operating Expenses, and Net Income or Loss. Each of these sections must be a clear table.
154
+ The Revenue section must contain a single table showing only the 'Total Revenue'. Do NOT create a table that itemizes or lists individual income sources.
155
  The report must also include a "Key Highlights" section with bullet points and a final "Summary" paragraph.
156
  Use the provided JSON data for all financial figures.
157
  For the Net Income or Loss table, if the net position is negative, display the amount in parentheses.
 
191
 
192
  for element in soup.find_all(True):
193
  if element.name in ['h1', 'h2', 'h3']:
194
+ level = int(element.name)
195
  font_size = {1: 16, 2: 14, 3: 12}.get(level)
196
  pdf.set_font('helvetica', 'B', font_size)
197
  pdf.multi_cell(0, 10, element.get_text().strip())
 
211
  pdf.ln(2)
212
  for li in element.find_all('li'):
213
  pdf.set_font('helvetica', '', 11)
214
+ item_text = li.get_text().strip().replace('•', '-')
215
+ pdf.multi_cell(0, 5, f" - {item_text}")
216
  pdf.ln(1)
217
  pdf.ln(4)
218
  elif element.name == 'table':
 
233
  if is_total_row:
234
  pdf.set_font('helvetica', 'B', 10)
235
 
236
+ pdf.cell(col_widths, 7, row, border=1)
237
+ pdf.cell(col_widths, 7, row, border=1, align='R')
238
  pdf.ln()
239
 
240
  if is_total_row:
 
243
 
244
  st.info("Content added to PDF. Outputting PDF to buffer...")
245
 
 
246
  pdf_output = pdf.output()
247
 
248
  st.success("PDF report generated successfully.")