Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -140,7 +140,6 @@ def generate_financial_report(model, aggregated_data, start_date, end_date, stat
|
|
| 140 |
"""
|
| 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:
|
|
@@ -171,8 +170,8 @@ Separate the major sections with a horizontal rule.
|
|
| 171 |
|
| 172 |
def create_pdf_report(report_text):
|
| 173 |
"""
|
| 174 |
-
Creates a PDF from markdown text.
|
| 175 |
-
|
| 176 |
"""
|
| 177 |
if not report_text:
|
| 178 |
st.warning("Report text is empty, skipping PDF generation.")
|
|
@@ -191,8 +190,9 @@ def create_pdf_report(report_text):
|
|
| 191 |
|
| 192 |
for element in soup.find_all(True):
|
| 193 |
if element.name in ['h1', 'h2', 'h3']:
|
| 194 |
-
|
| 195 |
-
|
|
|
|
| 196 |
pdf.set_font('helvetica', 'B', font_size)
|
| 197 |
pdf.multi_cell(0, 10, element.get_text().strip())
|
| 198 |
pdf.ln(level * 2)
|
|
@@ -233,9 +233,11 @@ def create_pdf_report(report_text):
|
|
| 233 |
if is_total_row:
|
| 234 |
pdf.set_font('helvetica', 'B', 10)
|
| 235 |
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
|
|
|
|
|
|
| 239 |
|
| 240 |
if is_total_row:
|
| 241 |
pdf.set_font('helvetica', '', 10)
|
|
|
|
| 140 |
"""
|
| 141 |
st.info(f"Preparing to generate {statement_type} with pre-aggregated data...")
|
| 142 |
|
|
|
|
| 143 |
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.
|
| 144 |
|
| 145 |
Here is the financial data:
|
|
|
|
| 170 |
|
| 171 |
def create_pdf_report(report_text):
|
| 172 |
"""
|
| 173 |
+
Creates a PDF from markdown text. This version includes fixes for both the
|
| 174 |
+
ValueError from incorrect int conversion and the table rendering logic.
|
| 175 |
"""
|
| 176 |
if not report_text:
|
| 177 |
st.warning("Report text is empty, skipping PDF generation.")
|
|
|
|
| 190 |
|
| 191 |
for element in soup.find_all(True):
|
| 192 |
if element.name in ['h1', 'h2', 'h3']:
|
| 193 |
+
# --- BUG FIX 1: Correctly extract the number from the tag ---
|
| 194 |
+
level = int(element.name[1])
|
| 195 |
+
font_size = {1: 16, 2: 14, 3: 12}.get(level, 11)
|
| 196 |
pdf.set_font('helvetica', 'B', font_size)
|
| 197 |
pdf.multi_cell(0, 10, element.get_text().strip())
|
| 198 |
pdf.ln(level * 2)
|
|
|
|
| 233 |
if is_total_row:
|
| 234 |
pdf.set_font('helvetica', 'B', 10)
|
| 235 |
|
| 236 |
+
# --- BUG FIX 2: Correctly iterate through cells and widths ---
|
| 237 |
+
if len(row) == len(col_widths): # Ensure row has the correct number of cells
|
| 238 |
+
pdf.cell(col_widths[0], 7, row[0], border=1)
|
| 239 |
+
pdf.cell(col_widths[1], 7, row[1], border=1, align='R')
|
| 240 |
+
pdf.ln()
|
| 241 |
|
| 242 |
if is_total_row:
|
| 243 |
pdf.set_font('helvetica', '', 10)
|