Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
57 |
-
|
58 |
-
|
59 |
|
60 |
def load_history():
|
61 |
global history_df
|
62 |
if os.path.exists('chat_history.json'):
|
63 |
-
|
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 |
-
|
|
|
|
|
113 |
|
114 |
def download_history():
|
115 |
csv_buffer = io.StringIO()
|
116 |
-
history_df.
|
|
|
|
|
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}'
|