Spaces:
Runtime error
Runtime error
Add Hugging Face Spaces configuration and documentation
Browse files- Add HF_SPACES_SETUP.md with comprehensive setup guide
- Add .env.hf-spaces with HF-specific environment configuration
- Update .env.example with upload configuration
- Document storage options and troubleshooting steps
π€ Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Files changed (3)
- .env.example+7-4
- .env.hf-spacesAdded+20
- HF_SPACES_SETUP.mdAdded+141
3 unmodified lines456789101 unmodified line121314151617183 unmodified lines# Nebius AI Configuration (Required for AI features)NEBIUS_API_KEY=your_nebius_api_key_here# Modal Configuration (Optional - for distributed processing)MODAL_TOKEN_ID=your_modal_token_idMODAL_TOKEN_SECRET=your_modal_token_secretMODAL_BASE_URL=your_modal_endpoint1 unmodified line# GitHub Configuration (Optional - for repository search)GITHUB_TOKEN=your_github_personal_access_token# Node EnvironmentNODE_ENV=productionPORT=7860EOF < /dev/null3 unmodified lines456789101 unmodified line121314151617181920213 unmodified lines# Nebius AI Configuration (Required for AI features)NEBIUS_API_KEY=your_nebius_api_key_here# Modal Configuration (Optional - for distributed processing)MODAL_TOKEN_ID=your_modal_token_idMODAL_TOKEN_SECRET=your_modal_token_secretMODAL_BASE_URL=your_modal_endpoint1 unmodified line# GitHub Configuration (Optional - for repository search)GITHUB_TOKEN=your_github_personal_access_token# Upload Configuration# Set to 'true' to disable file uploadsDISABLE_UPLOADS=false# Node EnvironmentNODE_ENV=developmentPORT=5000
1234567891011121314151617181920# Hugging Face Spaces Environment Configuration# Use these settings in your HF Space secrets/environment
# API Keys (Add these to your Space secrets)# NEBIUS_API_KEY=your_nebius_api_key_here# MODAL_TOKEN_ID=your_modal_token_id_here # MODAL_TOKEN_SECRET=your_modal_token_secret_here# GITHUB_TOKEN=your_github_token_here
# File Upload Configuration# Uploads are enabled by default in HF Spaces# Only set this to 'true' if you want to disable uploads# DISABLE_UPLOADS=false
# Server ConfigurationNODE_ENV=productionPORT=7860
# Database and uploads will automatically use /tmp in HF Spaces# No additional configuration needed for storage123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141# Hugging Face Spaces Setup Guide
## Quick Setup
1. **Create a new Space** on Hugging Face with: - SDK: Docker - Hardware: CPU basic (or GPU if you need faster processing)
2. **Environment Variables/Secrets**: Add these to your Space's settings > Variables and Secrets: ``` NEBIUS_API_KEY=your_nebius_api_key MODAL_TOKEN_ID=your_modal_token_id MODAL_TOKEN_SECRET=your_modal_token_secret GITHUB_TOKEN=your_github_token ```
3. **Upload Control** (Optional): - By default, uploads are **enabled** in Spaces - To disable uploads, add: `DISABLE_UPLOADS=true`
## Storage in Hugging Face Spaces
### Persistent vs Temporary Storage
Hugging Face Spaces provide:- **Temporary storage**: `/tmp` directory (used by this app) - β
Survives app restarts - β
Suitable for uploads and database - β Not persistent across Space rebuilds - β Limited size (~10GB)
### How This App Handles Storage
The app automatically detects Hugging Face Spaces and:
1. **Database**: Stored in `/tmp/knowledgebridge.db`2. **Uploads**: Stored in `/tmp/uploads/`3. **Vector Indexes**: Stored in `/tmp/` via Modal
### Adding Persistent Storage (Advanced)
For truly persistent storage, you have these options:
#### Option 1: External Database```bash# Add to your Space environmentDATABASE_URL=postgresql://user:pass@host:port/db```
#### Option 2: Cloud Storage```bash# Add to your Space environment AWS_ACCESS_KEY_ID=your_keyAWS_SECRET_ACCESS_KEY=your_secretS3_BUCKET=your_bucket```
#### Option 3: Hugging Face Hub (Git LFS)For large files, use Git LFS:```bashgit lfs track "*.pdf" "*.db"git add .gitattributes```
## Troubleshooting
### "File uploads disabled" Error
If you see this error, check:
1. **Environment Detection**: Look for this log message: ``` π Environment check: { NODE_ENV: 'production', DISABLE_UPLOADS: undefined, isHuggingFaceSpace: true, hasWritableStorage: true, isDocumentUploadEnabled: true } ```
2. **Force Enable**: Add this environment variable: ``` ENABLE_UPLOADS=true ```
3. **Check Logs**: Look for these success messages: ``` β
Created uploads directory: /tmp/uploads β
Upload directory is writable: /tmp/uploads β
Document uploads enabled - full functionality available ```
### Vector Search Issues
If vector search shows "disabled":
1. **Check Modal Integration**: Ensure Modal tokens are set2. **Check Logs**: Look for Modal API connectivity3. **Fallback**: The app will use text search if vector search fails
### Performance Optimization
For better performance in Spaces:
1. **Use GPU Hardware**: For faster AI processing2. **Enable Caching**: Vector indexes are cached in `/tmp`3. **Batch Operations**: Upload multiple files at once
## Environment Detection
The app detects Hugging Face Spaces using these environment variables:- `SPACE_ID`- `HF_SPACE_ID` - `HUGGINGFACE_SPACE_ID`- `HF_TOKEN`
When detected, uploads are automatically enabled regardless of other settings.
## Monitoring
Check your Space logs for these indicators:
### β
Successful Setup```β
Document uploads enabled - full functionality availableβ
Created uploads directory: /tmp/uploadsπ Environment check: { isHuggingFaceSpace: true, isDocumentUploadEnabled: true }```
### β Issues```β Failed to create or write to uploads directoryβΉοΈ Document uploads disabled - using fallback routesπ Environment check: { isDocumentUploadEnabled: false }```
## Support
If you encounter issues:
1. Check the Space logs for error messages2. Verify environment variables are set correctly 3. Test with a small PDF file first4. Check the app health endpoint: `/api/health`.env.example+7-4
.env.hf-spacesAdded+20
HF_SPACES_SETUP.mdAdded+141