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 <[email protected]>
- .env.example +7 -4
- .env.hf-spaces +20 -0
- HF_SPACES_SETUP.md +141 -0
.env.example
CHANGED
|
@@ -4,7 +4,7 @@
|
|
| 4 |
# Nebius AI Configuration (Required for AI features)
|
| 5 |
NEBIUS_API_KEY=your_nebius_api_key_here
|
| 6 |
|
| 7 |
-
# Modal Configuration (Optional - for distributed processing)
|
| 8 |
MODAL_TOKEN_ID=your_modal_token_id
|
| 9 |
MODAL_TOKEN_SECRET=your_modal_token_secret
|
| 10 |
MODAL_BASE_URL=your_modal_endpoint
|
|
@@ -12,7 +12,10 @@ MODAL_BASE_URL=your_modal_endpoint
|
|
| 12 |
# GitHub Configuration (Optional - for repository search)
|
| 13 |
GITHUB_TOKEN=your_github_personal_access_token
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
# Node Environment
|
| 16 |
-
NODE_ENV=
|
| 17 |
-
PORT=
|
| 18 |
-
EOF < /dev/null
|
|
|
|
| 4 |
# Nebius AI Configuration (Required for AI features)
|
| 5 |
NEBIUS_API_KEY=your_nebius_api_key_here
|
| 6 |
|
| 7 |
+
# Modal Configuration (Optional - for distributed processing)
|
| 8 |
MODAL_TOKEN_ID=your_modal_token_id
|
| 9 |
MODAL_TOKEN_SECRET=your_modal_token_secret
|
| 10 |
MODAL_BASE_URL=your_modal_endpoint
|
|
|
|
| 12 |
# GitHub Configuration (Optional - for repository search)
|
| 13 |
GITHUB_TOKEN=your_github_personal_access_token
|
| 14 |
|
| 15 |
+
# Upload Configuration
|
| 16 |
+
# Set to 'true' to disable file uploads
|
| 17 |
+
DISABLE_UPLOADS=false
|
| 18 |
+
|
| 19 |
# Node Environment
|
| 20 |
+
NODE_ENV=development
|
| 21 |
+
PORT=5000
|
|
|
.env.hf-spaces
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Hugging Face Spaces Environment Configuration
|
| 2 |
+
# Use these settings in your HF Space secrets/environment
|
| 3 |
+
|
| 4 |
+
# API Keys (Add these to your Space secrets)
|
| 5 |
+
# NEBIUS_API_KEY=your_nebius_api_key_here
|
| 6 |
+
# MODAL_TOKEN_ID=your_modal_token_id_here
|
| 7 |
+
# MODAL_TOKEN_SECRET=your_modal_token_secret_here
|
| 8 |
+
# GITHUB_TOKEN=your_github_token_here
|
| 9 |
+
|
| 10 |
+
# File Upload Configuration
|
| 11 |
+
# Uploads are enabled by default in HF Spaces
|
| 12 |
+
# Only set this to 'true' if you want to disable uploads
|
| 13 |
+
# DISABLE_UPLOADS=false
|
| 14 |
+
|
| 15 |
+
# Server Configuration
|
| 16 |
+
NODE_ENV=production
|
| 17 |
+
PORT=7860
|
| 18 |
+
|
| 19 |
+
# Database and uploads will automatically use /tmp in HF Spaces
|
| 20 |
+
# No additional configuration needed for storage
|
HF_SPACES_SETUP.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Hugging Face Spaces Setup Guide
|
| 2 |
+
|
| 3 |
+
## Quick Setup
|
| 4 |
+
|
| 5 |
+
1. **Create a new Space** on Hugging Face with:
|
| 6 |
+
- SDK: Docker
|
| 7 |
+
- Hardware: CPU basic (or GPU if you need faster processing)
|
| 8 |
+
|
| 9 |
+
2. **Environment Variables/Secrets**:
|
| 10 |
+
Add these to your Space's settings > Variables and Secrets:
|
| 11 |
+
|
| 12 |
+
```
|
| 13 |
+
NEBIUS_API_KEY=your_nebius_api_key
|
| 14 |
+
MODAL_TOKEN_ID=your_modal_token_id
|
| 15 |
+
MODAL_TOKEN_SECRET=your_modal_token_secret
|
| 16 |
+
GITHUB_TOKEN=your_github_token
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
3. **Upload Control** (Optional):
|
| 20 |
+
- By default, uploads are **enabled** in Spaces
|
| 21 |
+
- To disable uploads, add: `DISABLE_UPLOADS=true`
|
| 22 |
+
|
| 23 |
+
## Storage in Hugging Face Spaces
|
| 24 |
+
|
| 25 |
+
### Persistent vs Temporary Storage
|
| 26 |
+
|
| 27 |
+
Hugging Face Spaces provide:
|
| 28 |
+
- **Temporary storage**: `/tmp` directory (used by this app)
|
| 29 |
+
- β
Survives app restarts
|
| 30 |
+
- β
Suitable for uploads and database
|
| 31 |
+
- β Not persistent across Space rebuilds
|
| 32 |
+
- β Limited size (~10GB)
|
| 33 |
+
|
| 34 |
+
### How This App Handles Storage
|
| 35 |
+
|
| 36 |
+
The app automatically detects Hugging Face Spaces and:
|
| 37 |
+
|
| 38 |
+
1. **Database**: Stored in `/tmp/knowledgebridge.db`
|
| 39 |
+
2. **Uploads**: Stored in `/tmp/uploads/`
|
| 40 |
+
3. **Vector Indexes**: Stored in `/tmp/` via Modal
|
| 41 |
+
|
| 42 |
+
### Adding Persistent Storage (Advanced)
|
| 43 |
+
|
| 44 |
+
For truly persistent storage, you have these options:
|
| 45 |
+
|
| 46 |
+
#### Option 1: External Database
|
| 47 |
+
```bash
|
| 48 |
+
# Add to your Space environment
|
| 49 |
+
DATABASE_URL=postgresql://user:pass@host:port/db
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
#### Option 2: Cloud Storage
|
| 53 |
+
```bash
|
| 54 |
+
# Add to your Space environment
|
| 55 |
+
AWS_ACCESS_KEY_ID=your_key
|
| 56 |
+
AWS_SECRET_ACCESS_KEY=your_secret
|
| 57 |
+
S3_BUCKET=your_bucket
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
#### Option 3: Hugging Face Hub (Git LFS)
|
| 61 |
+
For large files, use Git LFS:
|
| 62 |
+
```bash
|
| 63 |
+
git lfs track "*.pdf" "*.db"
|
| 64 |
+
git add .gitattributes
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
## Troubleshooting
|
| 68 |
+
|
| 69 |
+
### "File uploads disabled" Error
|
| 70 |
+
|
| 71 |
+
If you see this error, check:
|
| 72 |
+
|
| 73 |
+
1. **Environment Detection**: Look for this log message:
|
| 74 |
+
```
|
| 75 |
+
π Environment check: { NODE_ENV: 'production', DISABLE_UPLOADS: undefined, isHuggingFaceSpace: true, hasWritableStorage: true, isDocumentUploadEnabled: true }
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
2. **Force Enable**: Add this environment variable:
|
| 79 |
+
```
|
| 80 |
+
ENABLE_UPLOADS=true
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
3. **Check Logs**: Look for these success messages:
|
| 84 |
+
```
|
| 85 |
+
β
Created uploads directory: /tmp/uploads
|
| 86 |
+
β
Upload directory is writable: /tmp/uploads
|
| 87 |
+
β
Document uploads enabled - full functionality available
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
### Vector Search Issues
|
| 91 |
+
|
| 92 |
+
If vector search shows "disabled":
|
| 93 |
+
|
| 94 |
+
1. **Check Modal Integration**: Ensure Modal tokens are set
|
| 95 |
+
2. **Check Logs**: Look for Modal API connectivity
|
| 96 |
+
3. **Fallback**: The app will use text search if vector search fails
|
| 97 |
+
|
| 98 |
+
### Performance Optimization
|
| 99 |
+
|
| 100 |
+
For better performance in Spaces:
|
| 101 |
+
|
| 102 |
+
1. **Use GPU Hardware**: For faster AI processing
|
| 103 |
+
2. **Enable Caching**: Vector indexes are cached in `/tmp`
|
| 104 |
+
3. **Batch Operations**: Upload multiple files at once
|
| 105 |
+
|
| 106 |
+
## Environment Detection
|
| 107 |
+
|
| 108 |
+
The app detects Hugging Face Spaces using these environment variables:
|
| 109 |
+
- `SPACE_ID`
|
| 110 |
+
- `HF_SPACE_ID`
|
| 111 |
+
- `HUGGINGFACE_SPACE_ID`
|
| 112 |
+
- `HF_TOKEN`
|
| 113 |
+
|
| 114 |
+
When detected, uploads are automatically enabled regardless of other settings.
|
| 115 |
+
|
| 116 |
+
## Monitoring
|
| 117 |
+
|
| 118 |
+
Check your Space logs for these indicators:
|
| 119 |
+
|
| 120 |
+
### β
Successful Setup
|
| 121 |
+
```
|
| 122 |
+
β
Document uploads enabled - full functionality available
|
| 123 |
+
β
Created uploads directory: /tmp/uploads
|
| 124 |
+
π Environment check: { isHuggingFaceSpace: true, isDocumentUploadEnabled: true }
|
| 125 |
+
```
|
| 126 |
+
|
| 127 |
+
### β Issues
|
| 128 |
+
```
|
| 129 |
+
β Failed to create or write to uploads directory
|
| 130 |
+
βΉοΈ Document uploads disabled - using fallback routes
|
| 131 |
+
π Environment check: { isDocumentUploadEnabled: false }
|
| 132 |
+
```
|
| 133 |
+
|
| 134 |
+
## Support
|
| 135 |
+
|
| 136 |
+
If you encounter issues:
|
| 137 |
+
|
| 138 |
+
1. Check the Space logs for error messages
|
| 139 |
+
2. Verify environment variables are set correctly
|
| 140 |
+
3. Test with a small PDF file first
|
| 141 |
+
4. Check the app health endpoint: `/api/health`
|