awacke1 commited on
Commit
a03bbab
·
verified ·
1 Parent(s): 60aa34b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -53,16 +53,14 @@ Respond in a manner that reflects your expertise and wisdom.
53
  history_df = pd.DataFrame(columns=['Timestamp', 'Request', 'Response'])
54
 
55
  def save_history():
56
- history_json = history_df.to_json(orient='records', date_format='iso')
57
- with open('chat_history.json', 'w') as f:
58
- json.dump(json.loads(history_json), f)
59
 
60
  def load_history():
61
  global history_df
62
  if os.path.exists('chat_history.json'):
63
- with open('chat_history.json', 'r') as f:
64
- history_data = json.load(f)
65
- history_df = pd.DataFrame(history_data)
66
  history_df['Timestamp'] = pd.to_datetime(history_df['Timestamp'])
67
  else:
68
  history_df = pd.DataFrame(columns=['Timestamp', 'Request', 'Response'])
@@ -109,11 +107,15 @@ async def respond(audio, model, seed):
109
  return tmp_path
110
 
111
  def display_history():
112
- return load_history()
 
 
113
 
114
  def download_history():
115
  csv_buffer = io.StringIO()
116
- history_df.to_csv(csv_buffer, index=False)
 
 
117
  csv_string = csv_buffer.getvalue()
118
  b64 = base64.b64encode(csv_string.encode()).decode()
119
  href = f'data:text/csv;base64,{b64}'
 
53
  history_df = pd.DataFrame(columns=['Timestamp', 'Request', 'Response'])
54
 
55
  def save_history():
56
+ history_df_copy = history_df.copy()
57
+ history_df_copy['Timestamp'] = history_df_copy['Timestamp'].astype(str)
58
+ history_df_copy.to_json('chat_history.json', orient='records')
59
 
60
  def load_history():
61
  global history_df
62
  if os.path.exists('chat_history.json'):
63
+ history_df = pd.read_json('chat_history.json', orient='records')
 
 
64
  history_df['Timestamp'] = pd.to_datetime(history_df['Timestamp'])
65
  else:
66
  history_df = pd.DataFrame(columns=['Timestamp', 'Request', 'Response'])
 
107
  return tmp_path
108
 
109
  def display_history():
110
+ df = load_history()
111
+ df['Timestamp'] = df['Timestamp'].astype(str)
112
+ return df
113
 
114
  def download_history():
115
  csv_buffer = io.StringIO()
116
+ history_df_copy = history_df.copy()
117
+ history_df_copy['Timestamp'] = history_df_copy['Timestamp'].astype(str)
118
+ history_df_copy.to_csv(csv_buffer, index=False)
119
  csv_string = csv_buffer.getvalue()
120
  b64 = base64.b64encode(csv_string.encode()).decode()
121
  href = f'data:text/csv;base64,{b64}'