Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -197,31 +197,45 @@ def save_conversation(chat_history, session_id, page_number):
|
|
| 197 |
base_path = "Chat_Store/conversation_logs"
|
| 198 |
if not os.path.exists(base_path):
|
| 199 |
os.makedirs(base_path)
|
|
|
|
| 200 |
|
| 201 |
filename = f"{base_path}/{session_id}_page{page_number}.json"
|
|
|
|
| 202 |
|
|
|
|
|
|
|
| 203 |
if os.path.exists(filename):
|
| 204 |
with open(filename, 'r') as file:
|
| 205 |
existing_data = json.load(file)
|
| 206 |
-
|
|
|
|
|
|
|
|
|
|
| 207 |
|
| 208 |
with open(filename, 'w') as file:
|
| 209 |
-
json.dump(
|
|
|
|
| 210 |
|
| 211 |
-
# Git operations
|
| 212 |
try:
|
| 213 |
# Change directory to Chat_Store for Git operations
|
| 214 |
original_dir = os.getcwd()
|
|
|
|
| 215 |
os.chdir('Chat_Store')
|
| 216 |
|
|
|
|
|
|
|
|
|
|
| 217 |
repo2.git_add(filename)
|
| 218 |
-
repo2.git_commit(f"Add conversation log for session {session_id}")
|
| 219 |
repo2.git_push()
|
| 220 |
|
| 221 |
# Change back to the original directory
|
| 222 |
os.chdir(original_dir)
|
|
|
|
| 223 |
except Exception as e:
|
| 224 |
-
|
|
|
|
| 225 |
|
| 226 |
|
| 227 |
|
|
|
|
| 197 |
base_path = "Chat_Store/conversation_logs"
|
| 198 |
if not os.path.exists(base_path):
|
| 199 |
os.makedirs(base_path)
|
| 200 |
+
st.text(f"Created directory: {base_path}")
|
| 201 |
|
| 202 |
filename = f"{base_path}/{session_id}_page{page_number}.json"
|
| 203 |
+
st.text(f"Filename for conversation log: {filename}")
|
| 204 |
|
| 205 |
+
# Check if the log file already exists
|
| 206 |
+
existing_data = []
|
| 207 |
if os.path.exists(filename):
|
| 208 |
with open(filename, 'r') as file:
|
| 209 |
existing_data = json.load(file)
|
| 210 |
+
st.text(f"Existing data found in file: {filename}")
|
| 211 |
+
|
| 212 |
+
# Append the new chat history to the existing data
|
| 213 |
+
full_chat_history = existing_data + chat_history
|
| 214 |
|
| 215 |
with open(filename, 'w') as file:
|
| 216 |
+
json.dump(full_chat_history, file, indent=4)
|
| 217 |
+
st.text(f"Conversation saved/updated in file: {filename}")
|
| 218 |
|
| 219 |
+
# Git operations
|
| 220 |
try:
|
| 221 |
# Change directory to Chat_Store for Git operations
|
| 222 |
original_dir = os.getcwd()
|
| 223 |
+
st.text(f"Original directory: {original_dir}")
|
| 224 |
os.chdir('Chat_Store')
|
| 225 |
|
| 226 |
+
st.text(f"Current working directory (after change): {os.getcwd()}")
|
| 227 |
+
st.text(f"Files in current directory: {os.listdir()}")
|
| 228 |
+
|
| 229 |
repo2.git_add(filename)
|
| 230 |
+
repo2.git_commit(f"Add/update conversation log for session {session_id}")
|
| 231 |
repo2.git_push()
|
| 232 |
|
| 233 |
# Change back to the original directory
|
| 234 |
os.chdir(original_dir)
|
| 235 |
+
st.text(f"Changed back to original directory: {original_dir}")
|
| 236 |
except Exception as e:
|
| 237 |
+
st.error(f"Error during Git operations: {e}")
|
| 238 |
+
|
| 239 |
|
| 240 |
|
| 241 |
|