BladeSzaSza Claude commited on
Commit
05ff752
·
1 Parent(s): 28c5901

Fix HuggingFace Spaces storage permissions for DigiPal deployment

Browse files

- Update production config to use /data instead of /app/data for persistent storage
- Add graceful error handling for directory creation in HF Spaces environment
- Prevent permission errors during app initialization

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>

Files changed (1) hide show
  1. config.py +15 -6
config.py CHANGED
@@ -119,14 +119,15 @@ class DigiPalConfig:
119
 
120
  def _load_production_config(self):
121
  """Production environment configuration"""
122
- self.database.path = "/app/data/digipal.db"
123
- self.database.backup_dir = "/app/data/backups"
 
124
 
125
  self.gradio.debug = False
126
  self.gradio.share = False
127
 
128
  self.logging.level = "INFO"
129
- self.logging.file_path = "/app/logs/digipal.log"
130
 
131
  self.security.session_timeout_hours = 12
132
  self.security.rate_limit_per_minute = 30
@@ -193,11 +194,19 @@ class DigiPalConfig:
193
 
194
  def _validate_config(self):
195
  """Validate configuration settings"""
196
- # Ensure required directories exist
197
- Path(self.database.backup_dir).mkdir(parents=True, exist_ok=True)
 
 
 
 
 
198
 
199
  if self.logging.file_path:
200
- Path(self.logging.file_path).parent.mkdir(parents=True, exist_ok=True)
 
 
 
201
 
202
  # Validate port ranges
203
  if not (1024 <= self.gradio.server_port <= 65535):
 
119
 
120
  def _load_production_config(self):
121
  """Production environment configuration"""
122
+ # Use /data for HuggingFace Spaces persistent storage
123
+ self.database.path = "/data/digipal.db"
124
+ self.database.backup_dir = "/data/backups"
125
 
126
  self.gradio.debug = False
127
  self.gradio.share = False
128
 
129
  self.logging.level = "INFO"
130
+ self.logging.file_path = "/data/logs/digipal.log"
131
 
132
  self.security.session_timeout_hours = 12
133
  self.security.rate_limit_per_minute = 30
 
194
 
195
  def _validate_config(self):
196
  """Validate configuration settings"""
197
+ # Ensure required directories exist (only if writable)
198
+ try:
199
+ Path(self.database.backup_dir).mkdir(parents=True, exist_ok=True)
200
+ except (PermissionError, OSError) as e:
201
+ # In HuggingFace Spaces, directories may be created automatically
202
+ # or may not be writable during initialization
203
+ logging.warning(f"Could not create backup directory {self.database.backup_dir}: {e}")
204
 
205
  if self.logging.file_path:
206
+ try:
207
+ Path(self.logging.file_path).parent.mkdir(parents=True, exist_ok=True)
208
+ except (PermissionError, OSError) as e:
209
+ logging.warning(f"Could not create log directory {Path(self.logging.file_path).parent}: {e}")
210
 
211
  # Validate port ranges
212
  if not (1024 <= self.gradio.server_port <= 65535):