mfraz commited on
Commit
51b14bd
·
verified ·
1 Parent(s): 2aa66f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -36
app.py CHANGED
@@ -1,87 +1,96 @@
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
@@ -90,5 +99,8 @@ if uploaded_file is not None:
90
  generate_income_statement(data)
91
  generate_cash_flow(data)
92
  generate_balance_sheet(data)
 
 
 
93
 
94
 
 
1
  import streamlit as st
2
  import pandas as pd
 
3
  from docx import Document
4
 
5
  # Function to load data from CSV, Excel, or DOCX
6
  def load_data(file):
7
+ try:
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 = [para.text for para in doc.paragraphs if para.text.strip()] # Remove empty lines
15
+ return pd.DataFrame(data, columns=["Text"])
16
+ else:
17
+ st.error("Unsupported file format. Please upload a CSV, Excel, or DOCX file.")
18
+ return None
19
+ except Exception as e:
20
+ st.error(f"Error loading file: {e}")
21
  return None
22
 
23
+ # Function to generate general journal entries
24
  def generate_general_entries(data):
25
+ st.subheader("General Journal Entries")
26
+ if data.empty:
27
+ st.error("No data available for journal entries.")
28
+ return
29
+ st.write(data)
30
 
31
  # Function to generate ledger
32
  def generate_ledger(data):
33
  st.subheader("Ledger")
34
+ required_columns = {"Account", "Amount"}
35
+ if required_columns.issubset(data.columns):
36
  ledger = data.groupby("Account")["Amount"].sum().reset_index()
37
  st.write(ledger)
38
  else:
39
+ st.error(f"Missing columns for ledger: {required_columns - set(data.columns)}")
40
 
41
  # Function to generate income statement
42
  def generate_income_statement(data):
43
  st.subheader("Income Statement")
44
+ required_columns = {"Revenue", "Expenses"}
45
+ if required_columns.issubset(data.columns):
46
  total_revenue = data["Revenue"].sum()
47
  total_expenses = data["Expenses"].sum()
48
  net_income = total_revenue - total_expenses
49
+ st.write(f"**Total Revenue:** ${total_revenue:,.2f}")
50
+ st.write(f"**Total Expenses:** ${total_expenses:,.2f}")
51
+ st.write(f"**Net Income:** ${net_income:,.2f}")
52
  else:
53
+ st.error(f"Missing columns for income statement: {required_columns - set(data.columns)}")
54
 
55
  # Function to generate cash flow statement
56
  def generate_cash_flow(data):
57
  st.subheader("Cash Flow Statement")
58
+ required_columns = {"Cash Inflow", "Cash Outflow"}
59
+ if required_columns.issubset(data.columns):
60
  total_inflow = data["Cash Inflow"].sum()
61
  total_outflow = data["Cash Outflow"].sum()
62
  net_cash_flow = total_inflow - total_outflow
63
+ st.write(f"**Total Cash Inflow:** ${total_inflow:,.2f}")
64
+ st.write(f"**Total Cash Outflow:** ${total_outflow:,.2f}")
65
+ st.write(f"**Net Cash Flow:** ${net_cash_flow:,.2f}")
66
  else:
67
+ st.error(f"Missing columns for cash flow statement: {required_columns - set(data.columns)}")
68
 
69
  # Function to generate balance sheet
70
  def generate_balance_sheet(data):
71
  st.subheader("Balance Sheet")
72
+ required_columns = {"Assets", "Liabilities", "Equity"}
73
+ if required_columns.issubset(data.columns):
74
  total_assets = data["Assets"].sum()
75
  total_liabilities = data["Liabilities"].sum()
76
  total_equity = data["Equity"].sum()
77
+ st.write(f"**Total Assets:** ${total_assets:,.2f}")
78
+ st.write(f"**Total Liabilities:** ${total_liabilities:,.2f}")
79
+ st.write(f"**Total Equity:** ${total_equity:,.2f}")
80
  else:
81
+ st.error(f"Missing columns for balance sheet: {required_columns - set(data.columns)}")
82
 
83
  # Streamlit App
84
+ st.title("📊 Financial Statement Generator")
85
 
86
  # File upload
87
  uploaded_file = st.file_uploader("Upload a CSV, Excel, or DOCX file", type=["csv", "xlsx", "docx"])
88
 
89
  if uploaded_file is not None:
90
  data = load_data(uploaded_file)
91
+
92
+ if data is not None and not data.empty:
93
+ st.write("### Uploaded Data Preview:")
94
  st.write(data.head())
95
 
96
  # Generate financial statements
 
99
  generate_income_statement(data)
100
  generate_cash_flow(data)
101
  generate_balance_sheet(data)
102
+ else:
103
+ st.error("The uploaded file contains no usable data.")
104
+
105
 
106