Spaces:
Runtime error
Runtime error
Update config/settings.py
Browse files- config/settings.py +15 -6
config/settings.py
CHANGED
|
@@ -9,8 +9,8 @@ IS_HF_SPACE = os.getenv('SPACE_ID') is not None
|
|
| 9 |
|
| 10 |
# Base directories
|
| 11 |
if IS_HF_SPACE:
|
| 12 |
-
# Use
|
| 13 |
-
BASE_DIR = Path(
|
| 14 |
else:
|
| 15 |
BASE_DIR = Path(__file__).resolve().parent.parent
|
| 16 |
|
|
@@ -21,10 +21,19 @@ CHAT_IMAGES_DIR = DATA_DIR / "chat_images"
|
|
| 21 |
|
| 22 |
# Create directories if they don't exist
|
| 23 |
for directory in [DATA_DIR, CHAT_HISTORIES_DIR, CHAT_IMAGES_DIR]:
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
# Ensure directories are writable
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
# API Settings - Get from HuggingFace secrets
|
| 30 |
ANTHROPIC_API_KEY = os.getenv('ANTHROPIC_API_KEY')
|
|
|
|
| 9 |
|
| 10 |
# Base directories
|
| 11 |
if IS_HF_SPACE:
|
| 12 |
+
# Use a directory in the HF space
|
| 13 |
+
BASE_DIR = Path('/data')
|
| 14 |
else:
|
| 15 |
BASE_DIR = Path(__file__).resolve().parent.parent
|
| 16 |
|
|
|
|
| 21 |
|
| 22 |
# Create directories if they don't exist
|
| 23 |
for directory in [DATA_DIR, CHAT_HISTORIES_DIR, CHAT_IMAGES_DIR]:
|
| 24 |
+
try:
|
| 25 |
+
directory.mkdir(parents=True, exist_ok=True)
|
| 26 |
+
# Ensure directories are writable
|
| 27 |
+
if directory.exists():
|
| 28 |
+
os.chmod(directory, 0o777)
|
| 29 |
+
except Exception as e:
|
| 30 |
+
st.warning(f"Could not create or modify directory {directory}: {str(e)}")
|
| 31 |
+
# Fallback to temporary directory if needed
|
| 32 |
+
if str(directory).startswith(str(BASE_DIR)):
|
| 33 |
+
new_path = Path('/tmp') / directory.relative_to(BASE_DIR)
|
| 34 |
+
new_path.mkdir(parents=True, exist_ok=True)
|
| 35 |
+
if IS_HF_SPACE:
|
| 36 |
+
directory = new_path
|
| 37 |
|
| 38 |
# API Settings - Get from HuggingFace secrets
|
| 39 |
ANTHROPIC_API_KEY = os.getenv('ANTHROPIC_API_KEY')
|