cryogenic22 commited on
Commit
13836e0
·
verified ·
1 Parent(s): 59ed66b

Update config/settings.py

Browse files
Files changed (1) hide show
  1. 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 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
 
@@ -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
- 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')
 
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')