mfraz commited on
Commit
17a7a8f
·
verified ·
1 Parent(s): 4753944

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -13
app.py CHANGED
@@ -2,36 +2,53 @@
2
 
3
  import streamlit as st
4
  import pandas as pd
 
5
 
6
  def process_financial_data(file):
7
  try:
8
- df = pd.read_csv(file)
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
- income_statement = df[df['Type'] == 'Income Statement']
11
- balance_sheet = df[df['Type'] == 'Balance Sheet']
12
- cash_flow = df[df['Type'] == 'Cash Flow Statement']
13
-
14
- return income_statement, balance_sheet, cash_flow
 
 
15
  except Exception as e:
16
  st.error(f"Error processing file: {e}")
17
  return None, None, None
18
 
19
  st.title("Financial Accounting App")
20
- st.write("Upload a financial data file (CSV) to generate statements.")
21
 
22
- uploaded_file = st.file_uploader("Upload CSV file", type=["csv"])
23
 
24
  if uploaded_file is not None:
25
  income_stmt, balance_sht, cash_flw = process_financial_data(uploaded_file)
26
 
27
  if income_stmt is not None:
28
- st.subheader("Income Statement")
29
  st.dataframe(income_stmt)
30
 
31
- st.subheader("Balance Sheet")
32
- st.dataframe(balance_sht)
 
33
 
34
- st.subheader("Cash Flow Statement")
35
- st.dataframe(cash_flw)
 
36
 
37
  st.write("Developed for financial statement analysis.")
 
2
 
3
  import streamlit as st
4
  import pandas as pd
5
+ import docx
6
 
7
  def process_financial_data(file):
8
  try:
9
+ if file.name.endswith('.csv'):
10
+ df = pd.read_csv(file)
11
+ elif file.name.endswith(('.xls', '.xlsx')):
12
+ df = pd.read_excel(file)
13
+ elif file.name.endswith('.docx'):
14
+ doc = docx.Document(file)
15
+ data = []
16
+ for para in doc.paragraphs:
17
+ data.append(para.text)
18
+ df = pd.DataFrame({'Content': data})
19
+ else:
20
+ st.error("Unsupported file format. Please upload a CSV, Excel, or Word document.")
21
+ return None, None, None
22
 
23
+ if 'Type' in df.columns:
24
+ income_statement = df[df['Type'] == 'Income Statement']
25
+ balance_sheet = df[df['Type'] == 'Balance Sheet']
26
+ cash_flow = df[df['Type'] == 'Cash Flow Statement']
27
+ return income_statement, balance_sheet, cash_flow
28
+ else:
29
+ return df, None, None
30
  except Exception as e:
31
  st.error(f"Error processing file: {e}")
32
  return None, None, None
33
 
34
  st.title("Financial Accounting App")
35
+ st.write("Upload a financial data file (CSV, Excel, Word) to generate statements.")
36
 
37
+ uploaded_file = st.file_uploader("Upload a file", type=["csv", "xls", "xlsx", "docx"])
38
 
39
  if uploaded_file is not None:
40
  income_stmt, balance_sht, cash_flw = process_financial_data(uploaded_file)
41
 
42
  if income_stmt is not None:
43
+ st.subheader("Processed Data")
44
  st.dataframe(income_stmt)
45
 
46
+ if balance_sht is not None:
47
+ st.subheader("Balance Sheet")
48
+ st.dataframe(balance_sht)
49
 
50
+ if cash_flw is not None:
51
+ st.subheader("Cash Flow Statement")
52
+ st.dataframe(cash_flw)
53
 
54
  st.write("Developed for financial statement analysis.")