Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
File size: 10,044 Bytes
896453f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | # HuggingFace Dataset Publishing Guide
Share your jurisdiction discovery datasets and run outputs on HuggingFace Hub for public collaboration!
---
## π― What Gets Published
### Available Datasets
| Dataset | Description | Size | Update Frequency |
|---------|-------------|------|------------------|
| **census-gid** | Census Bureau Government Integrated Directory | 90,735 jurisdictions | Annual |
| **gov-domains** | CISA .gov domain master list | 15,000+ domains | Daily* |
| **nces-schools** | NCES school district data | 13,000+ districts | Annual |
| **discovered-urls** | Discovered government URLs with metadata | Varies | Per run |
| **scraping-targets** | Prioritized scraping targets | Varies | Per run |
\* Daily on CISA side, you update as needed
---
## π§ Setup
### 1. Get HuggingFace Token
Visit: https://huggingface.co/settings/tokens
**Create a Write Token:**
1. Click "New token"
2. **Name:** "open-navigator-upload"
3. **Token type:** Write β οΈ (required for publishing)
4. **Repository permissions:** All repositories
5. Copy the token (starts with `hf_`)
**Why Write Access?**
- Creates dataset repositories on HuggingFace
- Uploads Parquet files with your scraped data
- Updates dataset cards and metadata
- Read-only tokens cannot publish datasets
### 2. Configure Environment
Add to your `.env` file:
```bash
# HuggingFace Configuration
HUGGINGFACE_TOKEN=hf_your_write_token_here
HF_ORGANIZATION=CommunityOne # Optional: your org name
HF_DATASET_PREFIX=open-navigator
```
### 3. Install Dependencies
```bash
pip install datasets huggingface-hub
```
---
## π Publishing Datasets
### Publish All Datasets
```bash
python main.py publish-to-hf --dataset all
```
**Output:**
```
π Publishing datasets to HuggingFace Hub...
π Published Datasets:
β census: https://huggingface.co/datasets/CommunityOne/open-navigator-census-gid
β gov_domains: https://huggingface.co/datasets/CommunityOne/open-navigator-gov-domains
β nces_schools: https://huggingface.co/datasets/CommunityOne/open-navigator-nces-schools
β discovered_urls: https://huggingface.co/datasets/CommunityOne/open-navigator-discovered-urls
β scraping_targets: https://huggingface.co/datasets/CommunityOne/open-navigator-scraping-targets
π Publishing complete!
```
### Publish Individual Datasets
```bash
# Publish census data only
python main.py publish-to-hf --dataset census
# Publish discovered URLs
python main.py publish-to-hf --dataset discovered-urls
# Publish .gov domains
python main.py publish-to-hf --dataset gov-domains
# Publish school districts
python main.py publish-to-hf --dataset nces-schools
# Publish scraping targets
python main.py publish-to-hf --dataset scraping-targets
```
### Options
**Make datasets private:**
```bash
python main.py publish-to-hf --dataset all --private
```
**Sample census data (faster for testing):**
```bash
python main.py publish-to-hf --dataset census --sample
```
---
## π¦ Programmatic Publishing
Use the publisher directly in Python:
```python
from pipeline.huggingface_publisher import HuggingFacePublisher
# Initialize publisher
publisher = HuggingFacePublisher(token="hf_your_token")
# Publish specific dataset
result = publisher.publish_discovered_urls(private=False)
print(f"Published to: {result['url']}")
# Publish all datasets
results = publisher.publish_all(private=False, sample_census=False)
for name, info in results.items():
print(f"{name}: {info['url']}")
```
---
## π Accessing Published Datasets
### View on HuggingFace Hub
Visit your dataset pages:
- https://huggingface.co/datasets/YOUR_ORG/open-navigator-census-gid
- https://huggingface.co/datasets/YOUR_ORG/open-navigator-gov-domains
- https://huggingface.co/datasets/YOUR_ORG/open-navigator-discovered-urls
### Load in Python
```python
from datasets import load_dataset
# Load census data
census = load_dataset("CommunityOne/open-navigator-census-gid")
# Load discovered URLs
urls = load_dataset("CommunityOne/open-navigator-discovered-urls")
# Access specific split
counties = census["counties"]
print(f"Total counties: {len(counties)}")
```
### Load in R
```r
library(datasets)
# Load dataset
census <- load_dataset("CommunityOne/open-navigator-census-gid")
# View data
head(census$counties)
```
### Access via API
```bash
curl https://datasets-server.huggingface.co/rows \
-d dataset=CommunityOne/open-navigator-census-gid \
-d config=counties \
-d split=train
```
---
## π Dataset Structure
### Census GID
**Splits:** `counties`, `municipalities`, `townships`, `school_districts`, `special_districts`
**Columns:**
- `jurisdiction_id`: Unique identifier
- `jurisdiction_name`: Official name
- `state_name`: State
- `county_name`: County (if applicable)
- `population`: Population count
- `fips_code`: FIPS code
### .gov Domains
**Single split:** `train`
**Columns:**
- `Domain Name`: Official .gov domain
- `Domain Type`: City, County, State, School District, etc.
- `Organization Name`: Government entity name
- `State`: State abbreviation
### Discovered URLs
**Single split:** `train`
**Columns:**
- `jurisdiction_id`: Link to jurisdiction
- `jurisdiction_name`: Government entity
- `state`: State
- `homepage_url`: Discovered homepage
- `minutes_url`: Meeting minutes page (if found)
- `discovery_method`: gsa_registry, pattern_match, not_found
- `confidence_score`: 0.0-1.0
- `cms_platform`: Granicus, CivicClerk, etc. (if detected)
- `last_verified`: Timestamp
---
## π Update Workflow
### After Each Discovery Run
```bash
# Run discovery
python main.py discover-jurisdictions
# Publish updated datasets
python main.py publish-to-hf --dataset discovered-urls
python main.py publish-to-hf --dataset scraping-targets
```
### Monthly Updates
```bash
# Re-ingest source data
python main.py discover-jurisdictions --bronze-only
# Publish refreshed datasets
python main.py publish-to-hf --dataset census
python main.py publish-to-hf --dataset gov-domains
python main.py publish-to-hf --dataset nces-schools
```
---
## π Dataset Cards
Each published dataset includes auto-generated metadata:
```yaml
dataset_info:
features:
- name: jurisdiction_name
dtype: string
- name: state
dtype: string
splits:
- name: train
num_examples: 90735
license: cc-by-4.0
task_categories:
- text-classification
- information-retrieval
language:
- en
tags:
- government
- open-data
- civic-tech
- jurisdiction-discovery
- oral-health-policy
```
---
## π€ Collaboration Features
### Dataset Discussions
Enable community discussions on your dataset pages for:
- Questions and answers
- Error reporting
- Feature requests
- Use case sharing
### Versioning
HuggingFace automatically tracks versions:
- Each push creates a new commit
- View version history on dataset page
- Pin to specific version in code:
```python
dataset = load_dataset(
"CommunityOne/open-navigator-discovered-urls",
revision="main" # or specific commit hash
)
```
### Dataset Viewer
HuggingFace provides automatic dataset preview:
- Browse first 100 rows
- Filter and search
- Export to CSV/JSON
- Embed in documentation
---
## π‘ Best Practices
### Privacy Considerations
- β
**Public datasets:** Census, CISA, NCES data (already public)
- β
**Discovered URLs:** Government website URLs (public)
- β οΈ **Scraped content:** Consider using `--private` flag
- β **PII data:** Never publish personal information
### Storage Limits
- Free tier: Unlimited public datasets
- Size limit: ~100GB per dataset (contact HF for larger)
- Recommend splitting very large datasets
### Naming Conventions
Your datasets will be named:
```
{organization}/{prefix}-{dataset-name}
Examples:
CommunityOne/open-navigator-census-gid
CommunityOne/open-navigator-discovered-urls
```
---
## π Use Cases
**For Researchers:**
```python
# Load all discovered government URLs
urls = load_dataset("CommunityOne/open-navigator-discovered-urls")
high_confidence = urls.filter(lambda x: x['confidence_score'] > 0.8)
```
**For Civic Hackers:**
```python
# Get all .gov domains by type
domains = load_dataset("CommunityOne/open-navigator-gov-domains")
counties = domains.filter(lambda x: x['Domain Type'] == 'County')
```
**For Data Scientists:**
```python
# Analyze jurisdiction coverage
census = load_dataset("CommunityOne/open-navigator-census-gid")
import pandas as pd
df = pd.DataFrame(census["counties"])
df.groupby("state_name")["population"].sum()
```
---
## π― Example: Complete Publishing Workflow
```bash
# 1. Run discovery
python main.py discover-jurisdictions --limit 1000
# 2. Check what you have
python main.py discovery-stats
# 3. Test publish with sample data
python main.py publish-to-hf --dataset census --sample --private
# 4. Publish public datasets
python main.py publish-to-hf --dataset all
# 5. View on HuggingFace
open https://huggingface.co/datasets/CommunityOne/open-navigator-discovered-urls
```
---
## π Troubleshooting
### Authentication Error
```
β Configuration error: HuggingFace token required
```
**Solution:** Set `HUGGINGFACE_TOKEN` in `.env` file
### Repository Not Found
```
β Failed to create repo: 404 Not Found
```
**Solution:**
- Check organization name in `.env`
- Verify token has write access
- Create organization on HuggingFace first
### Import Error
```
β HuggingFace libraries not installed!
```
**Solution:**
```bash
pip install datasets huggingface-hub
```
### Large Dataset Timeout
For very large datasets (>1M rows), publish in batches:
```python
publisher = HuggingFacePublisher()
publisher.publish_census_data(sample_size=100000) # Publish 100k at a time
```
---
## π Additional Resources
- **HuggingFace Datasets Docs:** https://huggingface.co/docs/datasets
- **Dataset Card Guide:** https://huggingface.co/docs/hub/datasets-cards
- **Hub Python Library:** https://huggingface.co/docs/huggingface_hub
---
**Ready to share your jurisdiction discovery data with the world!** ππ¦·β¨
|