Download utils/config_loader.py from anique-1/Medisync: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/spaces/anique-1/Medisync/resolve/main/utils/config_loader.py
- Command line
-
hf download hf://spaces/anique-1/Medisync/utils/config_loader.py
-
curl -L -o config_loader.py https://huggingface.co/spaces/anique-1/Medisync/resolve/main/utils/config_loader.py
1.19 kB
| import os | |
| import json | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| SETTINGS_FILE = "settings.json" | |
| def load_settings_from_file(): | |
| if not os.path.exists(SETTINGS_FILE): | |
| return {} | |
| try: | |
| with open(SETTINGS_FILE, "r") as f: | |
| return json.load(f) | |
| except Exception as e: | |
| print(f"Error loading settings file: {e}") | |
| return {} | |
| def save_settings_to_file(settings): | |
| try: | |
| current_settings = load_settings_from_file() | |
| current_settings.update(settings) | |
| with open(SETTINGS_FILE, "w") as f: | |
| json.dump(current_settings, f, indent=4) | |
| return True | |
| except Exception as e: | |
| print(f"Error saving settings file: {e}") | |
| return False | |
| def get_setting(key, default=None): | |
| # 1. Check file settings | |
| file_settings = load_settings_from_file() | |
| if key in file_settings and file_settings[key]: | |
| return file_settings[key] | |
| # 2. Check environment variables | |
| # We reload dotenv to check if .env has changed (though usually requires restart) | |
| # create_ref: but os.environ is what matters. | |
| val = os.getenv(key) | |
| if val: | |
| return val | |
| return default | |