Spaces:
No application file
No application file
| import os | |
| from typing import Optional | |
| from pathlib import Path | |
| from dotenv import load_dotenv | |
| # Load .env file từ project root | |
| project_root = Path(__file__).resolve().parents[2] | |
| env_path = project_root / ".env" | |
| load_dotenv(env_path) | |
| class Settings: | |
| # API Settings (đơn giản) | |
| API_BASE_URL: str = os.getenv("API_BASE_URL", "http://localhost:3454/api") | |
| # Gemini AI Settings | |
| GEMINI_API_KEY: Optional[str] = os.getenv("GEMINI_API_KEY") | |
| # Model URLs (Hugging Face) | |
| HF_MODEL_BASE_URL: str = "https://huggingface.co/NGOC1712/transportation-models/resolve/main/" | |
| HF_MODEL_FILES: dict = { | |
| "xgboost_model": "xgboost_model.pkl", | |
| "label_encoders": "all_label_encoders.joblib", | |
| "shipment_encoders": "shipment_label_encoders.pkl", | |
| "scaler": "scaler_weight_freight.pkl" | |
| } | |
| HF_TOKEN: Optional[str] = os.getenv("ACCESS") | |
| FUNCTIONS_DIR: Path = Path(__file__).resolve().parents[1] / "domain" / "functions" | |
| # Logging Configuration | |
| LOG_LEVEL: str = "INFO" | |
| LOG_FILE_ENABLED: bool = True | |
| LOG_CONSOLE_ENABLED: bool = True | |
| LOG_ROTATION_SIZE: int = 10 * 1024 * 1024 # 10MB | |
| LOG_BACKUP_COUNT: int = 5 | |
| LOG_RETENTION_DAYS: int = 30 | |
| def get_predict_url(cls) -> str: | |
| """Lấy URL đầy đủ cho predict endpoint""" | |
| return f"{cls.API_BASE_URL}/predict-transportation" | |
| def get_chat_url(cls) -> str: | |
| """Lấy URL đầy đủ cho chat endpoint""" | |
| return f"{cls.API_BASE_URL}/chat" | |
| def validate_gemini_key(cls) -> bool: | |
| """Kiểm tra xem Gemini API key có được thiết lập không""" | |
| return cls.GEMINI_API_KEY is not None and len(cls.GEMINI_API_KEY.strip()) > 0 | |
| def get_gemini_config(cls) -> dict: | |
| return { | |
| "api_key": cls.GEMINI_API_KEY | |
| } | |
| # Global settings instance | |
| settings = Settings() | |