Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -53,12 +53,17 @@ 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_df.to_json('
|
|
|
|
|
57 |
|
58 |
def load_history():
|
59 |
global history_df
|
60 |
if os.path.exists('chat_history.json'):
|
61 |
-
|
|
|
|
|
|
|
62 |
else:
|
63 |
history_df = pd.DataFrame(columns=['Timestamp', 'Request', 'Response'])
|
64 |
return history_df
|
@@ -85,7 +90,7 @@ def models(text, model="Mixtral 8x7B", seed=42):
|
|
85 |
|
86 |
# Add the current interaction to the history DataFrame
|
87 |
new_row = pd.DataFrame({
|
88 |
-
'Timestamp': [datetime.now()
|
89 |
'Request': [text],
|
90 |
'Response': [output]
|
91 |
})
|
@@ -169,4 +174,4 @@ with gr.Blocks(css="style.css") as demo:
|
|
169 |
if __name__ == "__main__":
|
170 |
# Load history at startup
|
171 |
load_history()
|
172 |
-
demo.queue(max_size=200).launch(
|
|
|
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'])
|
69 |
return history_df
|
|
|
90 |
|
91 |
# Add the current interaction to the history DataFrame
|
92 |
new_row = pd.DataFrame({
|
93 |
+
'Timestamp': [datetime.now()],
|
94 |
'Request': [text],
|
95 |
'Response': [output]
|
96 |
})
|
|
|
174 |
if __name__ == "__main__":
|
175 |
# Load history at startup
|
176 |
load_history()
|
177 |
+
demo.queue(max_size=200).launch()
|