Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,109 +1,94 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
|
|
3 |
from docx import Document
|
4 |
-
from io import BytesIO
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
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
|
26 |
-
cash_flow = df[df['Type'] == 'Cash Flow Statement'] if 'Type' in df.columns else None
|
27 |
-
|
28 |
-
return ledger, journal, trial_balance, income_statement, balance_sheet, cash_flow
|
29 |
-
except Exception as e:
|
30 |
-
st.error(f"Error processing file: {e}")
|
31 |
-
return None, None, None, None, None, None
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
hdr_cells[i].text = col_name
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
-
|
67 |
-
|
68 |
-
buffer.seek(0)
|
69 |
-
return buffer
|
70 |
|
71 |
-
|
72 |
-
st.
|
73 |
-
|
74 |
-
uploaded_file = st.file_uploader("Upload a file", type=["csv", "xls", "xlsx", "docx"])
|
75 |
|
76 |
if uploaded_file is not None:
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
st.
|
81 |
-
st.dataframe(ledger)
|
82 |
-
|
83 |
-
if journal is not None:
|
84 |
-
st.subheader("Journal Entries")
|
85 |
-
st.dataframe(journal)
|
86 |
-
|
87 |
-
if trial_balance is not None:
|
88 |
-
st.subheader("Trial Balance")
|
89 |
-
st.dataframe(trial_balance)
|
90 |
-
|
91 |
-
if income_stmt is not None:
|
92 |
-
st.subheader("Income Statement")
|
93 |
-
st.dataframe(income_stmt)
|
94 |
-
|
95 |
-
if balance_sht is not None:
|
96 |
-
st.subheader("Balance Sheet")
|
97 |
-
st.dataframe(balance_sht)
|
98 |
-
|
99 |
-
if cash_flw is not None:
|
100 |
-
st.subheader("Cash Flow Statement")
|
101 |
-
st.dataframe(cash_flw)
|
102 |
-
|
103 |
-
if st.button("Download Financial Report as Word Document"):
|
104 |
-
doc_file = generate_word_report(ledger, journal, trial_balance, income_stmt, balance_sht, cash_flw)
|
105 |
-
st.download_button(label="Download Report", data=doc_file, file_name="Financial_Report.docx", mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document")
|
106 |
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
108 |
|
109 |
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
from docx import Document
|
|
|
5 |
|
6 |
+
# Function to load data from CSV, Excel, or DOCX
|
7 |
+
def load_data(file):
|
8 |
+
if file.type == "text/csv":
|
9 |
+
return pd.read_csv(file)
|
10 |
+
elif file.type == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
|
11 |
+
return pd.read_excel(file)
|
12 |
+
elif file.type == "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
|
13 |
+
doc = Document(file)
|
14 |
+
data = []
|
15 |
+
for para in doc.paragraphs:
|
16 |
+
data.append(para.text)
|
17 |
+
return pd.DataFrame(data, columns=["Text"])
|
18 |
+
else:
|
19 |
+
st.error("Unsupported file format. Please upload a CSV, Excel, or DOCX file.")
|
20 |
+
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
+
# Function to generate general entries
|
23 |
+
def generate_general_entries(data):
|
24 |
+
st.subheader("General Entries")
|
25 |
+
st.write(data.head()) # Display the first few rows of the data
|
26 |
|
27 |
+
# Function to generate ledger
|
28 |
+
def generate_ledger(data):
|
29 |
+
st.subheader("Ledger")
|
30 |
+
if "Account" in data.columns and "Amount" in data.columns:
|
31 |
+
ledger = data.groupby("Account")["Amount"].sum().reset_index()
|
32 |
+
st.write(ledger)
|
33 |
+
else:
|
34 |
+
st.error("The uploaded file must contain 'Account' and 'Amount' columns for ledger generation.")
|
|
|
35 |
|
36 |
+
# Function to generate income statement
|
37 |
+
def generate_income_statement(data):
|
38 |
+
st.subheader("Income Statement")
|
39 |
+
if "Revenue" in data.columns and "Expenses" in data.columns:
|
40 |
+
total_revenue = data["Revenue"].sum()
|
41 |
+
total_expenses = data["Expenses"].sum()
|
42 |
+
net_income = total_revenue - total_expenses
|
43 |
+
st.write(f"Total Revenue: {total_revenue}")
|
44 |
+
st.write(f"Total Expenses: {total_expenses}")
|
45 |
+
st.write(f"Net Income: {net_income}")
|
46 |
+
else:
|
47 |
+
st.error("The uploaded file must contain 'Revenue' and 'Expenses' columns for income statement generation.")
|
48 |
|
49 |
+
# Function to generate cash flow statement
|
50 |
+
def generate_cash_flow(data):
|
51 |
+
st.subheader("Cash Flow Statement")
|
52 |
+
if "Cash Inflow" in data.columns and "Cash Outflow" in data.columns:
|
53 |
+
total_inflow = data["Cash Inflow"].sum()
|
54 |
+
total_outflow = data["Cash Outflow"].sum()
|
55 |
+
net_cash_flow = total_inflow - total_outflow
|
56 |
+
st.write(f"Total Cash Inflow: {total_inflow}")
|
57 |
+
st.write(f"Total Cash Outflow: {total_outflow}")
|
58 |
+
st.write(f"Net Cash Flow: {net_cash_flow}")
|
59 |
+
else:
|
60 |
+
st.error("The uploaded file must contain 'Cash Inflow' and 'Cash Outflow' columns for cash flow statement generation.")
|
61 |
|
62 |
+
# Function to generate balance sheet
|
63 |
+
def generate_balance_sheet(data):
|
64 |
+
st.subheader("Balance Sheet")
|
65 |
+
if "Assets" in data.columns and "Liabilities" in data.columns and "Equity" in data.columns:
|
66 |
+
total_assets = data["Assets"].sum()
|
67 |
+
total_liabilities = data["Liabilities"].sum()
|
68 |
+
total_equity = data["Equity"].sum()
|
69 |
+
st.write(f"Total Assets: {total_assets}")
|
70 |
+
st.write(f"Total Liabilities: {total_liabilities}")
|
71 |
+
st.write(f"Total Equity: {total_equity}")
|
72 |
+
else:
|
73 |
+
st.error("The uploaded file must contain 'Assets', 'Liabilities', and 'Equity' columns for balance sheet generation.")
|
74 |
|
75 |
+
# Streamlit App
|
76 |
+
st.title("Financial Calculator 📊")
|
|
|
|
|
77 |
|
78 |
+
# File upload
|
79 |
+
uploaded_file = st.file_uploader("Upload a CSV, Excel, or DOCX file", type=["csv", "xlsx", "docx"])
|
|
|
|
|
80 |
|
81 |
if uploaded_file is not None:
|
82 |
+
data = load_data(uploaded_file)
|
83 |
+
if data is not None:
|
84 |
+
st.write("Uploaded Data Preview:")
|
85 |
+
st.write(data.head())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
+
# Generate financial statements
|
88 |
+
generate_general_entries(data)
|
89 |
+
generate_ledger(data)
|
90 |
+
generate_income_statement(data)
|
91 |
+
generate_cash_flow(data)
|
92 |
+
generate_balance_sheet(data)
|
93 |
|
94 |
|