saulsolis09 commited on
Commit
2571434
·
verified ·
1 Parent(s): 4bfad2e

Upload 3 files

Browse files
Files changed (2) hide show
  1. README.md +84 -6
  2. requirements.txt +1 -6
README.md CHANGED
@@ -1,13 +1,91 @@
1
  ---
2
- title: SubdivisionProgram2
3
- emoji: 🦀
4
- colorFrom: purple
5
- colorTo: pink
6
  sdk: gradio
7
  sdk_version: 6.19.0
8
- python_version: '3.13'
9
  app_file: app.py
10
  pinned: false
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Subdivision Cluster FIPS Validation
3
+ emoji: 🗺️
4
+ colorFrom: blue
5
+ colorTo: indigo
6
  sdk: gradio
7
  sdk_version: 6.19.0
8
+ python_version: "3.12"
9
  app_file: app.py
10
  pinned: false
11
  ---
12
 
13
+ # Subdivision Cluster / FIPS Validation
14
+
15
+ Ported from the Colab notebook
16
+ `LatestUndeterminedZipCityCensusTract70_Threshold_95_Clusters.ipynb`.
17
+
18
+ Upload one or more Excel files. The app:
19
+
20
+ 1. Merges them into one table.
21
+ 2. Validates every `(city, FIPS)` pair against the **Subdivision Program
22
+ Safety List** (the reference file).
23
+ 3. Fuzzy-clusters `LegalSubDivision` names (RapidFuzz).
24
+ 4. Fills city / ZIP / census-tract by majority vote per cluster.
25
+ 5. Returns the cities, zips, census-tracts, cluster, and full-output files,
26
+ plus the FIPS validation audit.
27
+
28
+ ## How the reference (safety) file is handled
29
+
30
+ The app does **not** accept the safety list as an upload — it's your trusted
31
+ whitelist, so it stays under your control. `get_safety_list_path()` resolves it
32
+ two ways:
33
+
34
+ ### Option A — bundle it in this repo (Space must be PRIVATE)
35
+
36
+ Commit the xlsx into the Space repo and name it
37
+ `Subdivision_Program_Safety_List.xlsx` (or set the `SAFETY_LIST_FILE` variable
38
+ to your filename). Then set the Space visibility to **Private** in Settings —
39
+ otherwise the file is publicly downloadable.
40
+
41
+ ### Option B — private dataset + token (recommended)
42
+
43
+ 1. Create a **private dataset** repo and upload the safety list there.
44
+ 2. In this Space, add these under Settings → **Variables and secrets**:
45
+ - Secret `HF_TOKEN` — a read access token.
46
+ - Variable `SAFETY_LIST_REPO` — e.g. `your-username/subdivision-safety-list`.
47
+ - Variable `SAFETY_LIST_REPO_FILE` — the filename inside that dataset
48
+ (optional; defaults to `Subdivision_Program_Safety_List.xlsx`).
49
+
50
+ The list is downloaded once at startup and cached. To update it, just replace
51
+ the file in the dataset — no app redeploy needed.
52
+
53
+ ### Optional per-run override (sidebar)
54
+
55
+ The sidebar's **"2. Upload Reference File (Optional)"** slot lets you swap in a
56
+ different safety list (xlsx or csv, same `City Name` + `Acceptable FIPS *`
57
+ columns) for a **single run** — handy for testing a candidate list before
58
+ committing it. It is not persisted and does not touch the server-side list.
59
+
60
+ Security note: because this lets anyone with access to the Space substitute the
61
+ whitelist at request time, it's only appropriate for a **private** Space whose
62
+ members you trust (which is the current setup). To lock the whitelist to the
63
+ server copy only, delete the `reference_in` component and the `reference_file`
64
+ branch in `run_pipeline` (it falls back to `load_whitelist()`).
65
+
66
+ ## Deploy
67
+
68
+ ```bash
69
+ # one-time
70
+ huggingface-cli login
71
+
72
+ # create the Space (or do it in the web UI: New Space -> Gradio)
73
+ huggingface-cli repo create subdivision-space --type space --space_sdk gradio
74
+
75
+ git clone https://huggingface.co/spaces/<your-username>/subdivision-space
76
+ cd subdivision-space
77
+ cp /path/to/app.py /path/to/requirements.txt /path/to/README.md .
78
+ git add .
79
+ git commit -m "Initial app"
80
+ git push
81
+ ```
82
+
83
+ The Space builds automatically on push.
84
+
85
+ ## Notes
86
+
87
+ - The "filter to single most-dominant county" toggle reproduces the notebook's
88
+ behavior. Turn it off to process every county in the upload at once
89
+ (clustering already runs per-county, so this is safe).
90
+ - Large outputs: the full CSV is written whole. On the free CPU tier (limited
91
+ RAM), very large merges may need the upgraded hardware tier.
requirements.txt CHANGED
@@ -1,10 +1,5 @@
1
- gradio>=4.0
2
  pandas>=2.0
3
  numpy>=1.24
4
  openpyxl>=3.1
5
  rapidfuzz>=3.0
6
- huggingface_hub>=0.23,<1.0
7
- pydantic>=2.0,<2.11
8
- fastapi<0.116
9
- starlette<1.0
10
- audioop-lts; python_version >= "3.13"
 
 
1
  pandas>=2.0
2
  numpy>=1.24
3
  openpyxl>=3.1
4
  rapidfuzz>=3.0
5
+ huggingface_hub>=0.23