Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@
|
|
3 |
import streamlit as st
|
4 |
import pandas as pd
|
5 |
from docx import Document
|
|
|
6 |
|
7 |
def process_financial_data(file):
|
8 |
try:
|
@@ -16,23 +17,53 @@ def process_financial_data(file):
|
|
16 |
df = pd.DataFrame({'Content': data})
|
17 |
else:
|
18 |
st.error("Unsupported file format. Please upload a CSV, Excel, or Word document.")
|
19 |
-
return None, None, None, None, None
|
20 |
|
21 |
# Creating Ledger
|
22 |
ledger = df[df['Type'] == 'Ledger'] if 'Type' in df.columns else None
|
23 |
|
24 |
-
# Creating Journal
|
25 |
journal = df[df['Type'] == 'Journal'] if 'Type' in df.columns else None
|
26 |
|
27 |
# Creating Financial Statements
|
|
|
28 |
income_statement = df[df['Type'] == 'Income Statement'] if 'Type' in df.columns else None
|
29 |
balance_sheet = df[df['Type'] == 'Balance Sheet'] if 'Type' in df.columns else None
|
30 |
cash_flow = df[df['Type'] == 'Cash Flow Statement'] if 'Type' in df.columns else None
|
31 |
|
32 |
-
return ledger, journal, income_statement, balance_sheet, cash_flow
|
33 |
except Exception as e:
|
34 |
st.error(f"Error processing file: {e}")
|
35 |
-
return None, None, None, None, None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
st.title("Comprehensive Financial Accounting App")
|
38 |
st.write("Upload a financial data file (CSV, Excel, Word) to generate Ledger, Journal, and Financial Statements.")
|
@@ -40,16 +71,20 @@ st.write("Upload a financial data file (CSV, Excel, Word) to generate Ledger, Jo
|
|
40 |
uploaded_file = st.file_uploader("Upload a file", type=["csv", "xls", "xlsx", "docx"])
|
41 |
|
42 |
if uploaded_file is not None:
|
43 |
-
ledger, journal, income_stmt, balance_sht, cash_flw = process_financial_data(uploaded_file)
|
44 |
|
45 |
if ledger is not None:
|
46 |
st.subheader("Ledger")
|
47 |
st.dataframe(ledger)
|
48 |
|
49 |
if journal is not None:
|
50 |
-
st.subheader("Journal")
|
51 |
st.dataframe(journal)
|
52 |
|
|
|
|
|
|
|
|
|
53 |
if income_stmt is not None:
|
54 |
st.subheader("Income Statement")
|
55 |
st.dataframe(income_stmt)
|
@@ -61,6 +96,10 @@ if uploaded_file is not None:
|
|
61 |
if cash_flw is not None:
|
62 |
st.subheader("Cash Flow Statement")
|
63 |
st.dataframe(cash_flw)
|
|
|
|
|
|
|
|
|
64 |
|
65 |
st.write("Developed for comprehensive financial analysis.")
|
66 |
|
|
|
3 |
import streamlit as st
|
4 |
import pandas as pd
|
5 |
from docx import Document
|
6 |
+
from io import BytesIO
|
7 |
|
8 |
def process_financial_data(file):
|
9 |
try:
|
|
|
17 |
df = pd.DataFrame({'Content': data})
|
18 |
else:
|
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
|
32 |
cash_flow = df[df['Type'] == 'Cash Flow Statement'] if 'Type' in df.columns else None
|
33 |
|
34 |
+
return ledger, journal, trial_balance, income_statement, balance_sheet, cash_flow
|
35 |
except Exception as e:
|
36 |
st.error(f"Error processing file: {e}")
|
37 |
+
return None, None, None, None, None, None
|
38 |
+
|
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)
|
66 |
+
return buffer
|
67 |
|
68 |
st.title("Comprehensive Financial Accounting App")
|
69 |
st.write("Upload a financial data file (CSV, Excel, Word) to generate Ledger, Journal, and Financial Statements.")
|
|
|
71 |
uploaded_file = st.file_uploader("Upload a file", type=["csv", "xls", "xlsx", "docx"])
|
72 |
|
73 |
if uploaded_file is not None:
|
74 |
+
ledger, journal, trial_balance, income_stmt, balance_sht, cash_flw = process_financial_data(uploaded_file)
|
75 |
|
76 |
if ledger is not None:
|
77 |
st.subheader("Ledger")
|
78 |
st.dataframe(ledger)
|
79 |
|
80 |
if journal is not None:
|
81 |
+
st.subheader("Journal Entries")
|
82 |
st.dataframe(journal)
|
83 |
|
84 |
+
if trial_balance is not None:
|
85 |
+
st.subheader("Trial Balance")
|
86 |
+
st.dataframe(trial_balance)
|
87 |
+
|
88 |
if income_stmt is not None:
|
89 |
st.subheader("Income Statement")
|
90 |
st.dataframe(income_stmt)
|
|
|
96 |
if cash_flw is not None:
|
97 |
st.subheader("Cash Flow Statement")
|
98 |
st.dataframe(cash_flw)
|
99 |
+
|
100 |
+
if st.button("Download Financial Report as Word Document"):
|
101 |
+
doc_file = generate_word_report(ledger, journal, trial_balance, income_stmt, balance_sht, cash_flw)
|
102 |
+
st.download_button(label="Download Report", data=doc_file, file_name="Financial_Report.docx", mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document")
|
103 |
|
104 |
st.write("Developed for comprehensive financial analysis.")
|
105 |
|