| import os | |
| from pydantic_settings import BaseSettings, SettingsConfigDict | |
| from urllib.parse import quote_plus | |
| class Settings(BaseSettings): | |
| """Application settings loaded from environment variables.""" | |
| # βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # Google API Keys | |
| # βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| pagespeed_api_key: str | |
| gemini_api_key: str | |
| # Qdrant (vector DB) connection | |
| qdrant_url: str | |
| qdrant_api_key: str | |
| qdrant_timeout: int = 60 | |
| # βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # MongoDB Configuration | |
| # βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| mongo_user: str | |
| mongo_password: str | |
| mongo_host: str | |
| mongo_db: str = "MAAS" | |
| mongo_collection: str = "chat_histories" | |
| def mongo_uri(self) -> str: | |
| """ | |
| Return a mongodb+srv URI for use with MongoClient. | |
| """ | |
| pw = quote_plus(self.mongo_password) | |
| return f"mongodb+srv://{self.mongo_user}:{pw}@{self.mongo_host}/{self.mongo_db}?retryWrites=true&w=majority" | |
| # βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # FastAPI Server Configuration | |
| # βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| host: str = "0.0.0.0" | |
| # --- FIX IS HERE --- | |
| # 1. Use "PORT" (uppercase) to match Cloud env variables | |
| # 2. Default to 7860 to match Hugging Face requirements | |
| port: int = int(os.getenv("PORT", 7860)) | |
| debug: bool = False | |
| # βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # App Metadata | |
| # βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| app_name: str = "PageSpeed Insights Report Generator" | |
| app_version: str = "1.0.0" | |
| app_description: str = ( | |
| "Professional API for generating PageSpeed Insights reports " | |
| "using Google's APIs and Gemini AI" | |
| ) | |
| model_config = SettingsConfigDict( | |
| env_file=".env", | |
| env_file_encoding="utf-8", | |
| extra="ignore", | |
| ) | |
| # Single shared Settings instance | |
| settings = Settings() |