Spaces:
Running
Running
Fix: Use /data directory for Hugging Face Spaces persistent storage
Browse files- HUGGINGFACE_DEBUG.md +179 -0
- app/api/data/route.ts +4 -1
- app/api/documents/generate/route.ts +4 -1
- app/api/documents/process/route.ts +4 -1
- app/api/files/route.ts +4 -2
- app/api/public/route.ts +4 -1
- app/api/public/upload/route.ts +4 -1
HUGGINGFACE_DEBUG.md
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Debugging Hugging Face Space Deployment
|
| 2 |
+
|
| 3 |
+
## Current Status
|
| 4 |
+
✅ Code successfully pushed to Hugging Face (commit: 265f878)
|
| 5 |
+
⏳ Space shows "Running" status - waiting for build/deployment
|
| 6 |
+
|
| 7 |
+
## Steps Completed
|
| 8 |
+
1. ✅ Merged `clean-master` into `master` branch
|
| 9 |
+
2. ✅ Pushed to GitHub (`origin/master`)
|
| 10 |
+
3. ✅ Pushed to Hugging Face (`huggingface/master` and `huggingface/main`)
|
| 11 |
+
|
| 12 |
+
## Debugging Steps
|
| 13 |
+
|
| 14 |
+
### 1. Check Build Logs on Hugging Face
|
| 15 |
+
1. Go to https://huggingface.co/spaces/MCP-1st-Birthday/Reuben_OS
|
| 16 |
+
2. Click on the **"Files"** tab
|
| 17 |
+
3. Look for **"Logs"** or **"Build"** section
|
| 18 |
+
4. Check for any errors during build
|
| 19 |
+
|
| 20 |
+
### 2. Common Issues & Solutions
|
| 21 |
+
|
| 22 |
+
#### **Issue: Space stuck on "Running"**
|
| 23 |
+
**Solution:**
|
| 24 |
+
- Wait 2-3 minutes for initial build
|
| 25 |
+
- Check if `Dockerfile` exists and is properly configured
|
| 26 |
+
- Verify `next.config.mjs` has correct settings
|
| 27 |
+
- Check if `package.json` dependencies can install
|
| 28 |
+
|
| 29 |
+
#### **Issue: Build fails with module errors**
|
| 30 |
+
**Solution:**
|
| 31 |
+
- Check that all imports are correct
|
| 32 |
+
- Verify no references to deleted files (SessionManager, etc.)
|
| 33 |
+
- Run `npm install` and `npm run build` locally first
|
| 34 |
+
|
| 35 |
+
#### **Issue: App loads but files don't appear**
|
| 36 |
+
**Solution:**
|
| 37 |
+
- The new passkey system requires user to:
|
| 38 |
+
1. Open File Manager
|
| 39 |
+
2. Click "Secure Data" in sidebar
|
| 40 |
+
3. Enter a passkey
|
| 41 |
+
4. Upload files
|
| 42 |
+
- For public files:
|
| 43 |
+
1. Click "Public Files" in sidebar
|
| 44 |
+
2. Upload files directly
|
| 45 |
+
|
| 46 |
+
### 3. Environment-Specific Issues
|
| 47 |
+
|
| 48 |
+
#### **Data Directory Permissions**
|
| 49 |
+
The app creates directories in `public/data/`:
|
| 50 |
+
```
|
| 51 |
+
public/
|
| 52 |
+
└── data/
|
| 53 |
+
├── public/ # Public files
|
| 54 |
+
└── {passkey}/ # Secure files per passkey
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
**Check on Hugging Face:**
|
| 58 |
+
- Hugging Face Spaces may have read-only file system
|
| 59 |
+
- Persistent storage requires special configuration
|
| 60 |
+
- May need to use `/data` directory instead
|
| 61 |
+
|
| 62 |
+
#### **Fix for Hugging Face Persistent Storage:**
|
| 63 |
+
Update these routes to use Hugging Face's `/data` directory:
|
| 64 |
+
|
| 65 |
+
**In `/app/api/data/route.ts`:**
|
| 66 |
+
```typescript
|
| 67 |
+
const DATA_DIR = process.env.SPACE_ID
|
| 68 |
+
? '/data'
|
| 69 |
+
: path.join(process.cwd(), 'public', 'data')
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
**In `/app/api/files/route.ts`:**
|
| 73 |
+
```typescript
|
| 74 |
+
const DATA_DIR = process.env.SPACE_ID
|
| 75 |
+
? '/data'
|
| 76 |
+
: path.join(process.cwd(), 'public', 'data')
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
**In `/app/api/public/route.ts`:**
|
| 80 |
+
```typescript
|
| 81 |
+
const DATA_DIR = process.env.SPACE_ID
|
| 82 |
+
? '/data'
|
| 83 |
+
: path.join(process.cwd(), 'public', 'data')
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
### 4. Force Rebuild on Hugging Face
|
| 87 |
+
|
| 88 |
+
If the space doesn't auto-rebuild:
|
| 89 |
+
1. Go to space settings
|
| 90 |
+
2. Click **"Factory Reboot"** to force a rebuild
|
| 91 |
+
3. OR make a small commit:
|
| 92 |
+
```bash
|
| 93 |
+
git commit --allow-empty -m "Trigger rebuild"
|
| 94 |
+
git push huggingface master:main
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
### 5. Check Space Configuration
|
| 98 |
+
|
| 99 |
+
Verify your space has correct settings:
|
| 100 |
+
- **SDK**: Docker or nodejs
|
| 101 |
+
- **SDK version**: 18 (for Node.js)
|
| 102 |
+
- **App port**: Should match your app (3000 for Next.js)
|
| 103 |
+
|
| 104 |
+
### 6. Local Testing vs Production
|
| 105 |
+
|
| 106 |
+
**Key Differences:**
|
| 107 |
+
- **Local**: Uses `public/data` directory
|
| 108 |
+
- **Hugging Face**: Should use `/data` directory for persistence
|
| 109 |
+
- **Local**: Hot reload works
|
| 110 |
+
- **Hugging Face**: Requires rebuild on each push
|
| 111 |
+
|
| 112 |
+
### 7. Verify the Deployment
|
| 113 |
+
|
| 114 |
+
Once the space loads:
|
| 115 |
+
1. **Test Public Files:**
|
| 116 |
+
- Open File Manager
|
| 117 |
+
- Click "Public Files"
|
| 118 |
+
- Try uploading a file
|
| 119 |
+
- Verify it appears in the list
|
| 120 |
+
|
| 121 |
+
2. **Test Secure Storage:**
|
| 122 |
+
- Click "Secure Data"
|
| 123 |
+
- Enter any passkey (e.g., "test123")
|
| 124 |
+
- Upload a file
|
| 125 |
+
- Lock and unlock with same passkey
|
| 126 |
+
- Files should persist
|
| 127 |
+
|
| 128 |
+
### 8. Common Error Messages
|
| 129 |
+
|
| 130 |
+
**"Module not found"**
|
| 131 |
+
- Missing dependency in package.json
|
| 132 |
+
- Run: `npm install <missing-package>`
|
| 133 |
+
- Commit and push
|
| 134 |
+
|
| 135 |
+
**"Build failed"**
|
| 136 |
+
- Check Hugging Face build logs
|
| 137 |
+
- Look for TypeScript errors
|
| 138 |
+
- Verify all imports
|
| 139 |
+
|
| 140 |
+
**"Cannot write to directory"**
|
| 141 |
+
- File system is read-only
|
| 142 |
+
- Need to use `/data` directory
|
| 143 |
+
- Apply the fixes in Section 3
|
| 144 |
+
|
| 145 |
+
### 9. Monitoring Build Progress
|
| 146 |
+
|
| 147 |
+
Watch the space status:
|
| 148 |
+
- **Building**: Code is being compiled
|
| 149 |
+
- **Running**: App is starting
|
| 150 |
+
- **Ready**: App is live and accessible
|
| 151 |
+
- **Error**: Build failed - check logs
|
| 152 |
+
|
| 153 |
+
### 10. Quick Checklist
|
| 154 |
+
|
| 155 |
+
- [ ] Code pushed to Hugging Face
|
| 156 |
+
- [ ] Space shows "Building" or "Running"
|
| 157 |
+
- [ ] Wait 2-3 minutes for initial build
|
| 158 |
+
- [ ] No errors in build logs
|
| 159 |
+
- [ ] Space shows "Ready" status
|
| 160 |
+
- [ ] Can access the URL
|
| 161 |
+
- [ ] File Manager loads
|
| 162 |
+
- [ ] Can upload to Public Files
|
| 163 |
+
- [ ] Can create passkey and upload to Secure Data
|
| 164 |
+
|
| 165 |
+
## Next Steps
|
| 166 |
+
|
| 167 |
+
1. **Wait** for the current build to complete (2-3 minutes)
|
| 168 |
+
2. **Check** the Hugging Face space URL
|
| 169 |
+
3. **Review** build logs if there are errors
|
| 170 |
+
4. **Apply** the `/data` directory fix if file uploads fail
|
| 171 |
+
5. **Test** the file upload functionality
|
| 172 |
+
|
| 173 |
+
## Getting Help
|
| 174 |
+
|
| 175 |
+
If issues persist:
|
| 176 |
+
1. Share the Hugging Face build logs
|
| 177 |
+
2. Share any browser console errors
|
| 178 |
+
3. Check if the space is "Ready" or still "Building"
|
| 179 |
+
4. Verify the space settings are correct
|
app/api/data/route.ts
CHANGED
|
@@ -3,7 +3,10 @@ import fs from 'fs'
|
|
| 3 |
import path from 'path'
|
| 4 |
import { writeFile, mkdir, unlink, readdir, stat } from 'fs/promises'
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
// Ensure data directory exists
|
| 9 |
if (!fs.existsSync(DATA_DIR)) {
|
|
|
|
| 3 |
import path from 'path'
|
| 4 |
import { writeFile, mkdir, unlink, readdir, stat } from 'fs/promises'
|
| 5 |
|
| 6 |
+
// Use /data for Hugging Face Spaces persistent storage, fallback to public/data for local dev
|
| 7 |
+
const DATA_DIR = process.env.SPACE_ID
|
| 8 |
+
? '/data'
|
| 9 |
+
: path.join(process.cwd(), 'public', 'data')
|
| 10 |
|
| 11 |
// Ensure data directory exists
|
| 12 |
if (!fs.existsSync(DATA_DIR)) {
|
app/api/documents/generate/route.ts
CHANGED
|
@@ -3,7 +3,10 @@ import { DocumentGenerator } from '@/lib/documentGenerators';
|
|
| 3 |
import fs from 'fs';
|
| 4 |
import path from 'path';
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
| 7 |
const PUBLIC_DIR = path.join(DATA_DIR, 'public');
|
| 8 |
|
| 9 |
// Ensure directories exist
|
|
|
|
| 3 |
import fs from 'fs';
|
| 4 |
import path from 'path';
|
| 5 |
|
| 6 |
+
// Use /data for Hugging Face Spaces persistent storage
|
| 7 |
+
const DATA_DIR = process.env.SPACE_ID
|
| 8 |
+
? '/data'
|
| 9 |
+
: path.join(process.cwd(), 'public', 'data');
|
| 10 |
const PUBLIC_DIR = path.join(DATA_DIR, 'public');
|
| 11 |
|
| 12 |
// Ensure directories exist
|
app/api/documents/process/route.ts
CHANGED
|
@@ -4,7 +4,10 @@ import ExcelJS from 'exceljs';
|
|
| 4 |
import fs from 'fs';
|
| 5 |
import path from 'path';
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
| 8 |
const PUBLIC_DIR = path.join(DATA_DIR, 'public');
|
| 9 |
|
| 10 |
export async function POST(request: NextRequest) {
|
|
|
|
| 4 |
import fs from 'fs';
|
| 5 |
import path from 'path';
|
| 6 |
|
| 7 |
+
// Use /data for Hugging Face Spaces persistent storage
|
| 8 |
+
const DATA_DIR = process.env.SPACE_ID
|
| 9 |
+
? '/data'
|
| 10 |
+
: path.join(process.cwd(), 'public', 'data');
|
| 11 |
const PUBLIC_DIR = path.join(DATA_DIR, 'public');
|
| 12 |
|
| 13 |
export async function POST(request: NextRequest) {
|
app/api/files/route.ts
CHANGED
|
@@ -2,8 +2,10 @@ import { NextRequest, NextResponse } from 'next/server'
|
|
| 2 |
import fs from 'fs'
|
| 3 |
import path from 'path'
|
| 4 |
|
| 5 |
-
// Use /data for persistent storage
|
| 6 |
-
const DATA_DIR =
|
|
|
|
|
|
|
| 7 |
const PUBLIC_DIR = path.join(DATA_DIR, 'public')
|
| 8 |
|
| 9 |
// Ensure directories exist
|
|
|
|
| 2 |
import fs from 'fs'
|
| 3 |
import path from 'path'
|
| 4 |
|
| 5 |
+
// Use /data for Hugging Face Spaces persistent storage
|
| 6 |
+
const DATA_DIR = process.env.SPACE_ID
|
| 7 |
+
? '/data'
|
| 8 |
+
: path.join(process.cwd(), 'public', 'data')
|
| 9 |
const PUBLIC_DIR = path.join(DATA_DIR, 'public')
|
| 10 |
|
| 11 |
// Ensure directories exist
|
app/api/public/route.ts
CHANGED
|
@@ -2,7 +2,10 @@ import { NextRequest, NextResponse } from 'next/server'
|
|
| 2 |
import fs from 'fs'
|
| 3 |
import path from 'path'
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
| 6 |
const PUBLIC_DIR = path.join(DATA_DIR, 'public')
|
| 7 |
|
| 8 |
// Ensure public directory exists
|
|
|
|
| 2 |
import fs from 'fs'
|
| 3 |
import path from 'path'
|
| 4 |
|
| 5 |
+
// Use /data for Hugging Face Spaces persistent storage
|
| 6 |
+
const DATA_DIR = process.env.SPACE_ID
|
| 7 |
+
? '/data'
|
| 8 |
+
: path.join(process.cwd(), 'public', 'data')
|
| 9 |
const PUBLIC_DIR = path.join(DATA_DIR, 'public')
|
| 10 |
|
| 11 |
// Ensure public directory exists
|
app/api/public/upload/route.ts
CHANGED
|
@@ -2,7 +2,10 @@ import { NextRequest, NextResponse } from 'next/server';
|
|
| 2 |
import fs from 'fs';
|
| 3 |
import path from 'path';
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
| 6 |
const PUBLIC_DIR = path.join(DATA_DIR, 'public');
|
| 7 |
|
| 8 |
// Ensure directory exists
|
|
|
|
| 2 |
import fs from 'fs';
|
| 3 |
import path from 'path';
|
| 4 |
|
| 5 |
+
// Use /data for Hugging Face Spaces persistent storage
|
| 6 |
+
const DATA_DIR = process.env.SPACE_ID
|
| 7 |
+
? '/data'
|
| 8 |
+
: path.join(process.cwd(), 'public', 'data');
|
| 9 |
const PUBLIC_DIR = path.join(DATA_DIR, 'public');
|
| 10 |
|
| 11 |
// Ensure directory exists
|