mfraz commited on
Commit
ab15141
·
verified ·
1 Parent(s): 63e83b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -11
app.py CHANGED
@@ -1,5 +1,3 @@
1
- # app.py
2
-
3
  import streamlit as st
4
  import pandas as pd
5
  from docx import Document
@@ -19,13 +17,9 @@ def process_financial_data(file):
19
  st.error("Unsupported file format. Please upload a CSV, Excel, or Word document.")
20
  return None, None, None, None, None, None
21
 
22
- # Creating Ledger
23
  ledger = df[df['Type'] == 'Ledger'] if 'Type' in df.columns else None
24
-
25
- # Creating Journal Entries
26
  journal = df[df['Type'] == 'Journal'] if 'Type' in df.columns else None
27
-
28
- # Creating Financial Statements
29
  trial_balance = df[df['Type'] == 'Trial Balance'] if 'Type' in df.columns else None
30
  income_statement = df[df['Type'] == 'Income Statement'] if 'Type' in df.columns else None
31
  balance_sheet = df[df['Type'] == 'Balance Sheet'] if 'Type' in df.columns else None
@@ -39,27 +33,36 @@ def process_financial_data(file):
39
  def generate_word_report(ledger, journal, trial_balance, income_stmt, balance_sht, cash_flw):
40
  doc = Document()
41
  doc.add_heading("Financial Report", level=1)
42
-
 
43
  def add_table(df, title):
44
- if df is not None:
45
  doc.add_heading(title, level=2)
46
  table = doc.add_table(rows=1, cols=len(df.columns))
 
 
47
  hdr_cells = table.rows[0].cells
48
  for i, col_name in enumerate(df.columns):
49
  hdr_cells[i].text = col_name
 
50
  for _, row in df.iterrows():
51
  row_cells = table.add_row().cells
52
  for i, val in enumerate(row):
53
  row_cells[i].text = str(val)
 
54
  doc.add_paragraph("\n")
55
-
 
 
 
 
56
  add_table(ledger, "Ledger")
57
  add_table(journal, "Journal Entries")
58
  add_table(trial_balance, "Trial Balance")
59
  add_table(income_stmt, "Income Statement")
60
  add_table(balance_sht, "Balance Sheet")
61
  add_table(cash_flw, "Cash Flow Statement")
62
-
63
  buffer = BytesIO()
64
  doc.save(buffer)
65
  buffer.seek(0)
@@ -103,3 +106,4 @@ if uploaded_file is not None:
103
 
104
  st.write("Developed for comprehensive financial analysis.")
105
 
 
 
 
 
1
  import streamlit as st
2
  import pandas as pd
3
  from docx import Document
 
17
  st.error("Unsupported file format. Please upload a CSV, Excel, or Word document.")
18
  return None, None, None, None, None, None
19
 
20
+ # Creating Financial Reports
21
  ledger = df[df['Type'] == 'Ledger'] if 'Type' in df.columns else None
 
 
22
  journal = df[df['Type'] == 'Journal'] if 'Type' in df.columns else None
 
 
23
  trial_balance = df[df['Type'] == 'Trial Balance'] if 'Type' in df.columns else None
24
  income_statement = df[df['Type'] == 'Income Statement'] if 'Type' in df.columns else None
25
  balance_sheet = df[df['Type'] == 'Balance Sheet'] if 'Type' in df.columns else None
 
33
  def generate_word_report(ledger, journal, trial_balance, income_stmt, balance_sht, cash_flw):
34
  doc = Document()
35
  doc.add_heading("Financial Report", level=1)
36
+ doc.add_paragraph("\nGenerated Financial Statements\n")
37
+
38
  def add_table(df, title):
39
+ if df is not None and not df.empty:
40
  doc.add_heading(title, level=2)
41
  table = doc.add_table(rows=1, cols=len(df.columns))
42
+ table.style = 'Table Grid'
43
+
44
  hdr_cells = table.rows[0].cells
45
  for i, col_name in enumerate(df.columns):
46
  hdr_cells[i].text = col_name
47
+
48
  for _, row in df.iterrows():
49
  row_cells = table.add_row().cells
50
  for i, val in enumerate(row):
51
  row_cells[i].text = str(val)
52
+
53
  doc.add_paragraph("\n")
54
+ else:
55
+ doc.add_heading(title, level=2)
56
+ doc.add_paragraph("No data available.\n")
57
+
58
+ # Add each financial statement to the document
59
  add_table(ledger, "Ledger")
60
  add_table(journal, "Journal Entries")
61
  add_table(trial_balance, "Trial Balance")
62
  add_table(income_stmt, "Income Statement")
63
  add_table(balance_sht, "Balance Sheet")
64
  add_table(cash_flw, "Cash Flow Statement")
65
+
66
  buffer = BytesIO()
67
  doc.save(buffer)
68
  buffer.seek(0)
 
106
 
107
  st.write("Developed for comprehensive financial analysis.")
108
 
109
+