Spaces:
Running
Running
| """ | |
| src/config.py β Central configuration loaded from environment variables. | |
| For local development: create a .env file (see .env.example). | |
| For Hugging Face Spaces: set these under Space Settings β Secrets/Variables. | |
| """ | |
| import os | |
| from pathlib import Path | |
| # βββ Load local .env if present (dev-mode only) ββββββββββββββββββββββββββββββ | |
| # override=True ensures .env values always win over any inherited empty env vars. | |
| # We try two locations: project root (relative to this file) and current working | |
| # directory, so the app works whether launched from the repo root or src/. | |
| try: | |
| from dotenv import load_dotenv | |
| _env_candidates = [ | |
| Path(__file__).parent.parent / ".env", # <project_root>/.env | |
| Path.cwd() / ".env", # wherever Streamlit was launched | |
| ] | |
| for _env_path in _env_candidates: | |
| if _env_path.exists(): | |
| load_dotenv(_env_path, override=True) | |
| break | |
| except ImportError: | |
| pass # python-dotenv is optional; HF Spaces inject vars directly | |
| # βββ LLM / Ollama settings ββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # MODEL_PROVIDER is always "ollama" β no other provider is supported. | |
| MODEL_PROVIDER: str = "ollama" | |
| # Defaults mirror the values in .env so the app works without an explicit | |
| # HF Secret if the .env file is present locally. | |
| MODEL_NAME: str = os.getenv("MODEL_NAME", "gpt-oss:120b") | |
| _raw_base_url: str = os.getenv("MODEL_BASE_URL", "https://ollama.com/v1") or "https://ollama.com/v1" | |
| MODEL_BASE_URL: str = _raw_base_url.rstrip("/") | |
| CHAT_COMPLETION_URL: str = MODEL_BASE_URL + "/chat/completions" | |
| OLLAMA_API_KEY: str = os.getenv("OLLAMA_API_KEY", "") | |
| MAX_TOKENS: int = int(os.getenv("MAX_TOKENS", "1024")) | |
| TEMPERATURE: float = float(os.getenv("TEMPERATURE", "0.7")) | |
| REQUEST_TIMEOUT: int = int(os.getenv("REQUEST_TIMEOUT", "60")) | |
| # βββ App display ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| APP_TITLE: str = "PharmGPT" | |
| APP_SUBTITLE: str = "AI-Powered Pharmaceutical & Medical Assistant" | |
| # βββ Storage paths ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| _project_root = Path(__file__).parent.parent | |
| DATA_DIR: Path = Path(os.getenv("DATA_DIR", str(_project_root / "data"))) | |
| LOGS_DIR: Path = Path(os.getenv("LOGS_DIR", str(_project_root / "logs"))) | |
| DB_PATH: Path = DATA_DIR / "pharmgpt.db" | |
| LOG_PATH: Path = LOGS_DIR / "pharmgpt.log" | |
| # Create directories on import so every module can rely on them existing | |
| DATA_DIR.mkdir(parents=True, exist_ok=True) | |
| LOGS_DIR.mkdir(parents=True, exist_ok=True) | |