llepogam commited on
Commit
76ff9fc
·
1 Parent(s): 029fde9

history file

Browse files
Files changed (1) hide show
  1. app.py +29 -9
app.py CHANGED
@@ -6,6 +6,8 @@ import numpy as np
6
  import requests
7
  from datetime import datetime
8
  import time
 
 
9
 
10
  ### Config
11
  st.set_page_config(
@@ -14,11 +16,30 @@ st.set_page_config(
14
  layout="wide"
15
  )
16
 
17
- # Initialize session state
 
 
 
18
  if 'history' not in st.session_state:
19
- st.session_state.history = []
20
- if 'api_health' not in st.session_state:
21
- st.session_state.api_health = None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  # Custom CSS
24
  st.markdown("""
@@ -195,8 +216,9 @@ if user_input:
195
  'timestamp': datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
196
  'text': user_input,
197
  'prediction': final_prediction,
198
- 'confidence': probability
199
  })
 
200
 
201
  # History Section
202
  if st.session_state.history:
@@ -209,16 +231,14 @@ if st.session_state.history:
209
  "text": "Input Text",
210
  "prediction": "Prediction",
211
  "Prediction Value": st.column_config.NumberColumn(
212
- "Confidence",
213
  format="%.2f"
214
  )
215
  },
216
  hide_index=True
217
  )
218
 
219
- if st.button("Clear History"):
220
- st.session_state.history = []
221
- st.experimental_rerun()
222
 
223
  # Footer
224
  st.markdown("---")
 
6
  import requests
7
  from datetime import datetime
8
  import time
9
+ import os
10
+
11
 
12
  ### Config
13
  st.set_page_config(
 
16
  layout="wide"
17
  )
18
 
19
+ # File path for history
20
+ HISTORY_FILE = "https://llepogam-app-history.s3.eu-north-1.amazonaws.com/history.csv"
21
+
22
+ # Initialize session state and load history
23
  if 'history' not in st.session_state:
24
+ if os.path.exists(HISTORY_FILE):
25
+ try:
26
+ history_df = pd.read_csv(HISTORY_FILE)
27
+ st.session_state.history = history_df.to_dict('records')
28
+ except Exception as e:
29
+ st.error(f"Error loading history: {str(e)}")
30
+ st.session_state.history = []
31
+ else:
32
+ st.session_state.history = []
33
+
34
+
35
+
36
+ def save_history():
37
+ """Save history to CSV file"""
38
+ try:
39
+ history_df = pd.DataFrame(st.session_state.history)
40
+ history_df.to_csv(HISTORY_FILE, index=False)
41
+ except Exception as e:
42
+ st.error(f"Error saving history: {str(e)}")
43
 
44
  # Custom CSS
45
  st.markdown("""
 
216
  'timestamp': datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
217
  'text': user_input,
218
  'prediction': final_prediction,
219
+ 'prediction_value': probability
220
  })
221
+ save_history()
222
 
223
  # History Section
224
  if st.session_state.history:
 
231
  "text": "Input Text",
232
  "prediction": "Prediction",
233
  "Prediction Value": st.column_config.NumberColumn(
234
+ "prediction_value",
235
  format="%.2f"
236
  )
237
  },
238
  hide_index=True
239
  )
240
 
241
+
 
 
242
 
243
  # Footer
244
  st.markdown("---")