Fix conversation saving with absolute paths
Browse files- Use absolute paths for file operations in Spaces
- Fixed duplicate import issue
- Ensure conversations are saved to correct location
- Both main and public files now use BASE_DIR
This fixes the issue where new conversations weren't being saved in the Hugging Face Space.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
__pycache__/conversation_tracker.cpython-312.pyc
CHANGED
|
Binary files a/__pycache__/conversation_tracker.cpython-312.pyc and b/__pycache__/conversation_tracker.cpython-312.pyc differ
|
|
|
conversation_tracker.py
CHANGED
|
@@ -6,7 +6,9 @@ from datetime import datetime
|
|
| 6 |
from typing import List, Dict, Any
|
| 7 |
|
| 8 |
# Konuşma geçmişini saklamak için
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
MAX_CONVERSATIONS = 100 # Son 100 konuşmayı sakla
|
| 11 |
|
| 12 |
def load_conversations():
|
|
@@ -33,12 +35,11 @@ def save_conversations(conversations):
|
|
| 33 |
|
| 34 |
# Also save to a backup location that Gradio can access
|
| 35 |
try:
|
| 36 |
-
import os
|
| 37 |
# Create a directory if it doesn't exist
|
| 38 |
-
os.makedirs(
|
| 39 |
-
with open(
|
| 40 |
json.dump(conversations, f, ensure_ascii=False, indent=2)
|
| 41 |
-
print("✅ Also saved to
|
| 42 |
except:
|
| 43 |
pass
|
| 44 |
|
|
|
|
| 6 |
from typing import List, Dict, Any
|
| 7 |
|
| 8 |
# Konuşma geçmişini saklamak için
|
| 9 |
+
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 10 |
+
CONVERSATIONS_FILE = os.path.join(BASE_DIR, "conversations.json")
|
| 11 |
+
PUBLIC_FILE = os.path.join(BASE_DIR, "public", "conversations.json")
|
| 12 |
MAX_CONVERSATIONS = 100 # Son 100 konuşmayı sakla
|
| 13 |
|
| 14 |
def load_conversations():
|
|
|
|
| 35 |
|
| 36 |
# Also save to a backup location that Gradio can access
|
| 37 |
try:
|
|
|
|
| 38 |
# Create a directory if it doesn't exist
|
| 39 |
+
os.makedirs(os.path.dirname(PUBLIC_FILE), exist_ok=True)
|
| 40 |
+
with open(PUBLIC_FILE, 'w', encoding='utf-8') as f:
|
| 41 |
json.dump(conversations, f, ensure_ascii=False, indent=2)
|
| 42 |
+
print(f"✅ Also saved to {PUBLIC_FILE}")
|
| 43 |
except:
|
| 44 |
pass
|
| 45 |
|
conversations.json
CHANGED
|
@@ -28,5 +28,10 @@
|
|
| 28 |
"timestamp": "2025-08-26T21:36:07.192249",
|
| 29 |
"user": "Test mesaj",
|
| 30 |
"bot": "Test cevap"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
}
|
| 32 |
]
|
|
|
|
| 28 |
"timestamp": "2025-08-26T21:36:07.192249",
|
| 29 |
"user": "Test mesaj",
|
| 30 |
"bot": "Test cevap"
|
| 31 |
+
},
|
| 32 |
+
{
|
| 33 |
+
"timestamp": "2025-08-26T21:39:46.024295",
|
| 34 |
+
"user": "Path test",
|
| 35 |
+
"bot": "Path test response"
|
| 36 |
}
|
| 37 |
]
|
public/conversations.json
CHANGED
|
@@ -28,5 +28,10 @@
|
|
| 28 |
"timestamp": "2025-08-26T21:36:07.192249",
|
| 29 |
"user": "Test mesaj",
|
| 30 |
"bot": "Test cevap"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
}
|
| 32 |
]
|
|
|
|
| 28 |
"timestamp": "2025-08-26T21:36:07.192249",
|
| 29 |
"user": "Test mesaj",
|
| 30 |
"bot": "Test cevap"
|
| 31 |
+
},
|
| 32 |
+
{
|
| 33 |
+
"timestamp": "2025-08-26T21:39:46.024295",
|
| 34 |
+
"user": "Path test",
|
| 35 |
+
"bot": "Path test response"
|
| 36 |
}
|
| 37 |
]
|