Quincy Hsieh commited on
Commit
6ee8606
Β·
1 Parent(s): dddc53b

Read config.json in the /data folder, instead of reading from the root

Browse files
Files changed (2) hide show
  1. README.md +25 -2
  2. app.py +9 -2
README.md CHANGED
@@ -484,9 +484,20 @@ hf sync ./data hf://buckets/millimanfrance/Example-App-Hackathon-Gustave-Eiffel-
484
 
485
  ## Configuration
486
 
487
- ### Step 1 β€” Edit `config.json`
488
 
489
- Open [`config.json`](config.json) at the project root and replace the placeholders with your Azure OpenAI resource details:
 
 
 
 
 
 
 
 
 
 
 
490
 
491
  ```json
492
  {
@@ -527,6 +538,18 @@ $env:AZURE_API_KEY = "your_azure_api_key_here"
527
 
528
  When deploying to Hugging Face Spaces, add it as a **Space Secret** (Settings β†’ Secrets β†’ New secret β†’ name it `AZURE_API_KEY`).
529
 
 
 
 
 
 
 
 
 
 
 
 
 
530
  ### Tunable Parameters
531
 
532
  The following constants in `app.py` can also be adjusted directly:
 
484
 
485
  ## Configuration
486
 
487
+ The application loads model configuration with the following priority:
488
 
489
+ 1. **`./data/config.json`** β€” the live runtime config (read at startup)
490
+ 2. **`./config.json`** (project root) β€” example/template file used as fallback when no runtime config exists; **never put real credentials here**
491
+
492
+ ### Step 1 β€” Create `data/config.json`
493
+
494
+ Copy the root template to `./data/` and fill in your Azure OpenAI resource details:
495
+
496
+ ```bash
497
+ cp config.json data/config.json
498
+ ```
499
+
500
+ Then edit `data/config.json`:
501
 
502
  ```json
503
  {
 
538
 
539
  When deploying to Hugging Face Spaces, add it as a **Space Secret** (Settings β†’ Secrets β†’ New secret β†’ name it `AZURE_API_KEY`).
540
 
541
+ ### Step 3 β€” Push `data/config.json` to the HF Bucket
542
+
543
+ `data/config.json` lives under `./data` so a normal bucket sync includes it automatically:
544
+
545
+ ```bash
546
+ hf sync ./data hf://buckets/millimanfrance/Example-App-Hackathon-Gustave-Eiffel-2026-storage --delete
547
+ ```
548
+
549
+ The Space container will then find it at `/data/config.json` on next restart.
550
+
551
+ > **Do not commit `data/config.json` to Git** β€” it contains endpoint URLs tied to your Azure resource. Add `data/config.json` to `.gitignore`. The root `config.json` is safe to commit as it only contains placeholder values.
552
+
553
  ### Tunable Parameters
554
 
555
  The following constants in `app.py` can also be adjusted directly:
app.py CHANGED
@@ -56,8 +56,15 @@ CHUNK_SIZE = 512
56
  CHUNK_OVERLAP = 50
57
  TOP_K_RESULTS = 3
58
 
59
- # Settings loaded from config.json
60
- _CONFIG_PATH = Path(__file__).parent / "config.json"
 
 
 
 
 
 
 
61
  with open(_CONFIG_PATH, encoding="utf-8") as _f:
62
  _config = json.load(_f)
63
 
 
56
  CHUNK_OVERLAP = 50
57
  TOP_K_RESULTS = 3
58
 
59
+ # Settings loaded from data/config.json (runtime config).
60
+ # Falls back to the root config.json which serves as the example/template.
61
+ _CONFIG_PATH = DATA_DIR / "config.json"
62
+ if not _CONFIG_PATH.exists():
63
+ _CONFIG_PATH = Path(__file__).parent / "config.json"
64
+ logger.warning(
65
+ f"No config.json found in {DATA_DIR} β€” falling back to root config.json (example file). "
66
+ "Copy config.json to the data directory and fill in your values for production use."
67
+ )
68
  with open(_CONFIG_PATH, encoding="utf-8") as _f:
69
  _config = json.load(_f)
70