Spaces:
Sleeping
Sleeping
π€ Hugging Face Dataset Setup Guide
Overview
This server now uses Hugging Face Dataset for persistent storage of device tokens instead of local files. This ensures that device data is preserved across Space restarts and provides better data management.
π Quick Setup
1. Generate Hugging Face Token
- Go to Hugging Face Settings
- Click "Create new token"
- Name:
houzou-notification-server
- Type: Write (required for dataset operations)
- Copy the token
2. Configure Space Secrets
- Go to your Space Settings β Secrets and variables
- Add these secrets:
HF_TOKEN = hf_your_token_here
HF_DATASET_ID = Detomo/houzou-devices (optional, defaults to this)
3. Required Secrets Summary
Your Space needs these secrets:
FIREBASE_SERVICE_ACCOUNT = {your firebase config JSON}
HF_TOKEN = hf_your_write_token_here
HF_DATASET_ID = Detomo/houzou-devices (optional)
π Dataset Structure
The dataset will be automatically created with:
datasets/Detomo/houzou-devices/
βββ README.md # Dataset documentation
βββ devices.json # Device tokens and metadata
devices.json Format:
[
[
"device-id-1",
{
"token": "fcm_token_here",
"lastUpdated": "2024-01-01T00:00:00.000Z",
"platform": "iOS",
"appVersion": "1.0.0",
"registered": true
}
]
]
π§ Features
β Automatic Dataset Management
- Creates dataset if it doesn't exist
- Handles permissions automatically
- Provides fallback to in-memory storage
β Persistent Storage
- Device tokens survive Space restarts
- Automatic backup to HF dataset
- Version control for device data
β Error Handling
- Graceful fallback if HF API is unavailable
- Detailed logging for troubleshooting
- Continues operation even if dataset access fails
π Verification
Check Dataset Status
curl https://your-space-url.hf.space/
Response includes:
{
"message": "Houzou Medical Notification Server",
"status": "running",
"hfDataset": {
"enabled": true,
"datasetId": "Detomo/houzou-devices",
"hasToken": true
},
"deviceCount": 5
}
View Dataset
- Go to: https://huggingface.co/datasets/Detomo/houzou-devices
- Check
devices.json
for your device data
π Troubleshooting
Dataset Not Created
- Verify
HF_TOKEN
has Write permissions - Check Space logs for error messages
- Ensure token is valid and not expired
Data Not Saving
- Check if HF API is responding
- Verify dataset permissions
- Server will continue with in-memory storage as fallback
Common Errors
403 Forbidden
- Token doesn't have write permissions
- Token is expired or invalid
404 Not Found
- Dataset doesn't exist (will be auto-created)
- Wrong dataset ID
Rate Limiting
- HF API has rate limits
- Server will retry automatically
π Migration from File Storage
If you're migrating from file-based storage:
- Backup existing data: Download your current
devices.json
- Set up HF dataset: Follow steps above
- Deploy updated server: The server will automatically use HF dataset
- Verify: Check that devices are loaded correctly
π Environment Variables
# Required
HF_TOKEN=hf_your_write_token_here
FIREBASE_SERVICE_ACCOUNT={"type":"service_account",...}
# Optional
HF_DATASET_ID=Detomo/houzou-devices
PORT=7860
NODE_ENV=production
π― Benefits
- β Persistent: Data survives Space restarts
- β Reliable: Automatic fallback mechanisms
- β Scalable: No file permission issues
- β Traceable: Version history in dataset
- β Secure: Tokens stored in HF infrastructure
π Links
Ready to deploy! Your notification server will now use HF Dataset for persistent storage. π