ClarzW commited on
Commit
0bf6dd7
·
verified ·
1 Parent(s): 4002895

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -22,19 +22,22 @@ def save_data(df):
22
  '''
23
  df.to_csv(DATA_FILE, index=False)
24
 
 
 
 
25
 
26
  # Initialize session state
27
  if 'expenses' not in st.session_state:
28
  st.session_state['expenses'] = load_data()
29
 
 
 
30
 
31
- # Add categories as required (TO-DO: Add input to append to this list? Might be too complicated for 30 minutes)
32
- categories = ['Food', 'Transport', 'Bills', 'Entertainment', 'Other']
33
 
34
  # Upload file from computer and not HuggingFace
35
  uploaded_file = st.file_uploader("Import Data")
36
 
37
- if uploaded_file is not None:
38
  # Check the file type based on the MIME type
39
  if uploaded_file.name.endswith('.csv'):
40
  new_data = pd.read_csv(uploaded_file)
@@ -45,12 +48,16 @@ if uploaded_file is not None:
45
  save_data(st.session_state['expenses']) # Ensures the HuggingFace storage contains this version
46
  st.success("CSV file successfully uploaded!")
47
 
48
- uploaded_file = ''
49
 
50
  else:
51
  st.error("File type is not supported. Please upload a CSV file.")
52
 
53
 
 
 
 
 
54
  st.title("Expense Tracker")
55
 
56
  with st.form("expense_form"):
 
22
  '''
23
  df.to_csv(DATA_FILE, index=False)
24
 
25
+ # Add categories as required (TO-DO: Add input to append to this list? Might be too complicated for 30 minutes)
26
+ categories = ['Food', 'Transport', 'Bills', 'Entertainment', 'Other']
27
+
28
 
29
  # Initialize session state
30
  if 'expenses' not in st.session_state:
31
  st.session_state['expenses'] = load_data()
32
 
33
+ if 'file_processed' not in st.session_state:
34
+ st.session_state['file_processed'] = False
35
 
 
 
36
 
37
  # Upload file from computer and not HuggingFace
38
  uploaded_file = st.file_uploader("Import Data")
39
 
40
+ if uploaded_file is not None and not st.session_state['file_processed']:
41
  # Check the file type based on the MIME type
42
  if uploaded_file.name.endswith('.csv'):
43
  new_data = pd.read_csv(uploaded_file)
 
48
  save_data(st.session_state['expenses']) # Ensures the HuggingFace storage contains this version
49
  st.success("CSV file successfully uploaded!")
50
 
51
+ st.session_state['file_processed'] = True
52
 
53
  else:
54
  st.error("File type is not supported. Please upload a CSV file.")
55
 
56
 
57
+
58
+
59
+
60
+
61
  st.title("Expense Tracker")
62
 
63
  with st.form("expense_form"):