cryogenic22 commited on
Commit
7a4e48d
·
verified ·
1 Parent(s): ca456a7

Update config/settings.py

Browse files
Files changed (1) hide show
  1. config/settings.py +19 -6
config/settings.py CHANGED
@@ -1,20 +1,33 @@
1
- # src/config/settings.py
2
 
3
  import os
4
  from pathlib import Path
 
 
 
 
5
 
6
  # Base directories
7
- BASE_DIR = Path(__file__).resolve().parent.parent.parent
 
 
 
 
 
 
8
  DATA_DIR = BASE_DIR / "data"
9
  CHAT_HISTORIES_DIR = DATA_DIR / "chat_histories"
10
  CHAT_IMAGES_DIR = DATA_DIR / "chat_images"
11
 
12
  # Create directories if they don't exist
13
- CHAT_HISTORIES_DIR.mkdir(parents=True, exist_ok=True)
14
- CHAT_IMAGES_DIR.mkdir(parents=True, exist_ok=True)
 
 
 
15
 
16
- # API Settings
17
- ANTHROPIC_API_KEY = os.getenv("ANTHROPIC_API_KEY")
18
  CLAUDE_MODEL = "claude-3-opus-20240229"
19
 
20
  # App Settings
 
1
+ # config/settings.py
2
 
3
  import os
4
  from pathlib import Path
5
+ import streamlit as st
6
+
7
+ # Check if we're running on HuggingFace Space
8
+ IS_HF_SPACE = os.getenv('SPACE_ID') is not None
9
 
10
  # Base directories
11
+ if IS_HF_SPACE:
12
+ # Use streamlit's cache directory for persistent storage in HF Spaces
13
+ BASE_DIR = Path(st.runtime.get_instance().cache_path)
14
+ else:
15
+ BASE_DIR = Path(__file__).resolve().parent.parent
16
+
17
+ # Data directories
18
  DATA_DIR = BASE_DIR / "data"
19
  CHAT_HISTORIES_DIR = DATA_DIR / "chat_histories"
20
  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
+ directory.mkdir(parents=True, exist_ok=True)
25
+ if IS_HF_SPACE:
26
+ # Ensure directories are writable in HF environment
27
+ os.chmod(directory, 0o777)
28
 
29
+ # API Settings - Get from HuggingFace secrets
30
+ ANTHROPIC_API_KEY = os.getenv('ANTHROPIC_API_KEY')
31
  CLAUDE_MODEL = "claude-3-opus-20240229"
32
 
33
  # App Settings