Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -71,14 +71,21 @@ def save_conversation():
|
|
71 |
"messages": st.session_state.messages,
|
72 |
"file_names": st.session_state.uploaded_file_names
|
73 |
}
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
76 |
|
77 |
# Function to load previous conversations
|
78 |
def load_conversations():
|
79 |
if os.path.exists("conversations.json"):
|
80 |
with open("conversations.json", "r") as f:
|
81 |
conversations = [json.loads(line) for line in f]
|
|
|
|
|
|
|
|
|
82 |
return conversations
|
83 |
return []
|
84 |
|
@@ -155,9 +162,9 @@ if st.session_state.show_conversations:
|
|
155 |
selected_indices = []
|
156 |
for i, conv in enumerate(conversations):
|
157 |
st.sidebar.write(f"Conversation {i + 1}:")
|
158 |
-
for message in conv
|
159 |
st.sidebar.write(f"{message['role']}: {message['content']}")
|
160 |
-
st.sidebar.write(f"Files: {', '.join(conv
|
161 |
# Checkbox for selecting conversation to delete
|
162 |
if st.sidebar.checkbox(f"Select Conversation {i + 1} for Deletion", key=f"delete_checkbox_{i}"):
|
163 |
selected_indices.append(i)
|
|
|
71 |
"messages": st.session_state.messages,
|
72 |
"file_names": st.session_state.uploaded_file_names
|
73 |
}
|
74 |
+
if isinstance(conversation_data, dict):
|
75 |
+
json.dump(conversation_data, f)
|
76 |
+
f.write("\n")
|
77 |
+
else:
|
78 |
+
print("Warning: Attempted to save a non-dictionary conversation_data:", conversation_data)
|
79 |
|
80 |
# Function to load previous conversations
|
81 |
def load_conversations():
|
82 |
if os.path.exists("conversations.json"):
|
83 |
with open("conversations.json", "r") as f:
|
84 |
conversations = [json.loads(line) for line in f]
|
85 |
+
# Ensure each conversation is a dictionary
|
86 |
+
for conv in conversations:
|
87 |
+
if not isinstance(conv, dict):
|
88 |
+
print("Warning: Loaded conversation is not a dictionary:", conv)
|
89 |
return conversations
|
90 |
return []
|
91 |
|
|
|
162 |
selected_indices = []
|
163 |
for i, conv in enumerate(conversations):
|
164 |
st.sidebar.write(f"Conversation {i + 1}:")
|
165 |
+
for message in conv.get('messages', []):
|
166 |
st.sidebar.write(f"{message['role']}: {message['content']}")
|
167 |
+
st.sidebar.write(f"Files: {', '.join(conv.get('file_names', []))}")
|
168 |
# Checkbox for selecting conversation to delete
|
169 |
if st.sidebar.checkbox(f"Select Conversation {i + 1} for Deletion", key=f"delete_checkbox_{i}"):
|
170 |
selected_indices.append(i)
|