Spaces:
Paused
Paused
Update config.py
Browse files
config.py
CHANGED
|
@@ -80,7 +80,7 @@ class Config:
|
|
| 80 |
"dir": self.directories["data"],
|
| 81 |
"name": "legal_documents.db",
|
| 82 |
"path": os.path.join(self.directories["data"], "legal_documents.db"),
|
| 83 |
-
"backup_interval": 3600 if self.is_hf_spaces else 86400,
|
| 84 |
}
|
| 85 |
|
| 86 |
@property
|
|
@@ -91,7 +91,7 @@ class Config:
|
|
| 91 |
"algorithm": "HS256",
|
| 92 |
"access_token_expire_minutes": int(os.getenv("ACCESS_TOKEN_EXPIRE_MINUTES", "30")),
|
| 93 |
"refresh_token_expire_days": int(os.getenv("REFRESH_TOKEN_EXPIRE_DAYS", "7")),
|
| 94 |
-
"bcrypt_rounds": 12 if not self.is_hf_spaces else 10,
|
| 95 |
}
|
| 96 |
|
| 97 |
@property
|
|
@@ -103,16 +103,16 @@ class Config:
|
|
| 103 |
"workers": 1 if self.is_hf_spaces else int(os.getenv("WORKERS", "4")),
|
| 104 |
"reload": self.is_development,
|
| 105 |
"log_level": os.getenv("LOG_LEVEL", "info").lower(),
|
| 106 |
-
"access_log": not self.is_hf_spaces,
|
| 107 |
}
|
| 108 |
|
| 109 |
@property
|
| 110 |
def ai_config(self) -> Dict[str, Any]:
|
| 111 |
-
"""AI/ML configuration"""
|
| 112 |
return {
|
| 113 |
"cache_dir": self.cache_dir,
|
| 114 |
-
"
|
| 115 |
-
"device": "cpu",
|
| 116 |
"max_workers": 1 if self.is_hf_spaces else 2,
|
| 117 |
"batch_size": 1 if self.is_hf_spaces else 4,
|
| 118 |
"timeout": 30 if self.is_hf_spaces else 60,
|
|
@@ -129,8 +129,7 @@ class Config:
|
|
| 129 |
"socket_timeout": 5,
|
| 130 |
"decode_responses": True,
|
| 131 |
"retry_on_timeout": True,
|
| 132 |
-
"
|
| 133 |
-
"fallback_to_memory": True, # Always fallback if Redis unavailable
|
| 134 |
}
|
| 135 |
|
| 136 |
@property
|
|
@@ -140,7 +139,7 @@ class Config:
|
|
| 140 |
"level": logging.INFO if not self.is_development else logging.DEBUG,
|
| 141 |
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
| 142 |
"file": os.path.join(self.directories["logs"], "legal_dashboard.log") if not self.is_hf_spaces else None,
|
| 143 |
-
"max_bytes": 10 * 1024 * 1024,
|
| 144 |
"backup_count": 5,
|
| 145 |
}
|
| 146 |
|
|
@@ -152,13 +151,14 @@ class Config:
|
|
| 152 |
"DATABASE_PATH": self.database_config["path"],
|
| 153 |
"PYTHONPATH": self.base_dir,
|
| 154 |
|
| 155 |
-
# AI/ML
|
| 156 |
"HF_HOME": self.cache_dir,
|
| 157 |
-
"TRANSFORMERS_CACHE": self.cache_dir,
|
| 158 |
"HF_HUB_CACHE": self.cache_dir,
|
| 159 |
"TORCH_HOME": self.cache_dir,
|
|
|
|
| 160 |
"TOKENIZERS_PARALLELISM": "false",
|
| 161 |
-
"CUDA_VISIBLE_DEVICES": "",
|
| 162 |
|
| 163 |
# Performance
|
| 164 |
"OMP_NUM_THREADS": "1" if self.is_hf_spaces else "4",
|
|
@@ -181,7 +181,7 @@ class Config:
|
|
| 181 |
|
| 182 |
for key, value in env_vars.items():
|
| 183 |
os.environ[key] = value
|
| 184 |
-
if not key.startswith(("JWT_", "SECRET")):
|
| 185 |
self.logger.info(f"π§ {key}={value}")
|
| 186 |
else:
|
| 187 |
self.logger.info(f"π§ {key}=***")
|
|
|
|
| 80 |
"dir": self.directories["data"],
|
| 81 |
"name": "legal_documents.db",
|
| 82 |
"path": os.path.join(self.directories["data"], "legal_documents.db"),
|
| 83 |
+
"backup_interval": 3600 if self.is_hf_spaces else 86400,
|
| 84 |
}
|
| 85 |
|
| 86 |
@property
|
|
|
|
| 91 |
"algorithm": "HS256",
|
| 92 |
"access_token_expire_minutes": int(os.getenv("ACCESS_TOKEN_EXPIRE_MINUTES", "30")),
|
| 93 |
"refresh_token_expire_days": int(os.getenv("REFRESH_TOKEN_EXPIRE_DAYS", "7")),
|
| 94 |
+
"bcrypt_rounds": 12 if not self.is_hf_spaces else 10,
|
| 95 |
}
|
| 96 |
|
| 97 |
@property
|
|
|
|
| 103 |
"workers": 1 if self.is_hf_spaces else int(os.getenv("WORKERS", "4")),
|
| 104 |
"reload": self.is_development,
|
| 105 |
"log_level": os.getenv("LOG_LEVEL", "info").lower(),
|
| 106 |
+
"access_log": not self.is_hf_spaces,
|
| 107 |
}
|
| 108 |
|
| 109 |
@property
|
| 110 |
def ai_config(self) -> Dict[str, Any]:
|
| 111 |
+
"""AI/ML configuration - Updated for stability"""
|
| 112 |
return {
|
| 113 |
"cache_dir": self.cache_dir,
|
| 114 |
+
"ocr_model_name": "microsoft/trocr-base-printed", # Changed to 'base-printed' as it's more robust
|
| 115 |
+
"device": "cpu",
|
| 116 |
"max_workers": 1 if self.is_hf_spaces else 2,
|
| 117 |
"batch_size": 1 if self.is_hf_spaces else 4,
|
| 118 |
"timeout": 30 if self.is_hf_spaces else 60,
|
|
|
|
| 129 |
"socket_timeout": 5,
|
| 130 |
"decode_responses": True,
|
| 131 |
"retry_on_timeout": True,
|
| 132 |
+
"fallback_to_memory": True,
|
|
|
|
| 133 |
}
|
| 134 |
|
| 135 |
@property
|
|
|
|
| 139 |
"level": logging.INFO if not self.is_development else logging.DEBUG,
|
| 140 |
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
| 141 |
"file": os.path.join(self.directories["logs"], "legal_dashboard.log") if not self.is_hf_spaces else None,
|
| 142 |
+
"max_bytes": 10 * 1024 * 1024,
|
| 143 |
"backup_count": 5,
|
| 144 |
}
|
| 145 |
|
|
|
|
| 151 |
"DATABASE_PATH": self.database_config["path"],
|
| 152 |
"PYTHONPATH": self.base_dir,
|
| 153 |
|
| 154 |
+
# AI/ML - Unified cache paths
|
| 155 |
"HF_HOME": self.cache_dir,
|
| 156 |
+
"TRANSFORMERS_CACHE": self.cache_dir,
|
| 157 |
"HF_HUB_CACHE": self.cache_dir,
|
| 158 |
"TORCH_HOME": self.cache_dir,
|
| 159 |
+
"HF_TOKEN": os.getenv("HF_TOKEN", ""), # Added for authentication
|
| 160 |
"TOKENIZERS_PARALLELISM": "false",
|
| 161 |
+
"CUDA_VISIBLE_DEVICES": "",
|
| 162 |
|
| 163 |
# Performance
|
| 164 |
"OMP_NUM_THREADS": "1" if self.is_hf_spaces else "4",
|
|
|
|
| 181 |
|
| 182 |
for key, value in env_vars.items():
|
| 183 |
os.environ[key] = value
|
| 184 |
+
if not key.startswith(("JWT_", "SECRET", "HF_TOKEN")):
|
| 185 |
self.logger.info(f"π§ {key}={value}")
|
| 186 |
else:
|
| 187 |
self.logger.info(f"π§ {key}=***")
|