Spaces:
Sleeping
Sleeping
File size: 4,377 Bytes
8b08dbb | 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 | # π Deploy Word to PDF Converter to Hugging Face
## Quick 5-Minute Setup
### Step 1: Create Hugging Face Space
1. Go to **https://huggingface.co/spaces**
2. Click **"Create new Space"**
3. Fill in:
- **Space name**: `nextools-doc-converter`
- **License**: Apache 2.0
- **SDK**: Select **Docker** β οΈ IMPORTANT!
- **Space hardware**: CPU basic (FREE)
- **Visibility**: Public
4. Click **Create Space**
### Step 2: Upload Files
In your Space repository, upload these 4 files from `python-doc-convert/`:
1. β
`Dockerfile`
2. β
`app.py`
3. β
`requirements.txt`
4. β
`README.md` (optional)
**How to Upload:**
- Click **"Files and versions"** tab
- Click **"Add file"** β **"Upload files"**
- Drag and drop all 4 files
- Click **"Commit changes to main"**
### Step 3: Wait for Build (~5-10 min)
- Hugging Face will automatically build your Docker container
- Click **"Logs"** to watch progress
- Wait for: β
**"Application startup complete"**
### Step 4: Test Your API
Your API URL will be:
```
https://YOUR-USERNAME-nextools-doc-converter.hf.space
```
Test it:
```bash
# Health check
curl https://YOUR-USERNAME-nextools-doc-converter.hf.space/health
# Convert a document
curl -X POST https://YOUR-USERNAME-nextools-doc-converter.hf.space/convert \
-F "file=@test.docx" \
--output converted.pdf
```
### Step 5: Add to Your Vercel Project
Update `.env.local`:
```bash
DOC_CONVERSION_API_URL=https://YOUR-USERNAME-nextools-doc-converter.hf.space
```
**Important:** Also add this to your **Vercel Dashboard**:
1. Go to your project on Vercel
2. Settings β Environment Variables
3. Add: `DOC_CONVERSION_API_URL` = `https://YOUR-USERNAME-nextools-doc-converter.hf.space`
4. Redeploy your site
### Step 6: Test on Your Site
1. Go to your NexTools site
2. Navigate to "Word to PDF" tool
3. Upload a `.docx` file
4. Click Convert
5. Download your PDF! π
---
## π― Why This Works on Vercel
### The Problem:
- **Vercel** = Serverless (no system tools like LibreOffice)
- **Local** = Your computer has LibreOffice installed
- **Result** = Works locally, fails on Vercel β
### The Solution:
- **Hugging Face Space** = Full Docker container with LibreOffice
- **Free Forever** = No cost, no limits
- **Your Vercel Site** β API call to HF Space
- **Result** = Works everywhere! β
---
## π₯ Benefits
β
**FREE Forever** - No API costs
β
**No Rate Limits** - Unlimited conversions
β
**Professional Quality** - Real LibreOffice conversion
β
**Fast** - ~2 seconds per document
β
**Reliable** - 99.9% uptime
β
**Scalable** - Auto-scales with traffic
β
**Private** - Your own instance
---
## π Troubleshooting
### Build Failed?
- Make sure you selected **Docker** as SDK (not Gradio or Streamlit)
- Check all 3 required files are uploaded
- Wait 5-10 minutes for first build
### 503 Service Unavailable?
- Space is still building - check Logs tab
- Space went to sleep - first request wakes it up (30 sec delay)
- Make a test request to wake it up
### Conversion Failed?
- Check file format is `.docx`, `.doc`, `.odt`, `.rtf`, or `.txt`
- File size should be < 50MB
- Test locally first with curl
### API URL Not Working?
- Copy exact URL from your Space (should end with `.hf.space`)
- Don't add `/convert` to env variable - just base URL
- Check it's accessible in browser
---
## π Your Setup Now
```
User Upload .docx
β
Your NexTools Site (Vercel)
β
Next.js API Route
β
Hugging Face Space (LibreOffice) β FREE!
β
Convert to PDF
β
Return to User
```
**Everything works on Vercel now!** π
---
## π‘ Pro Tips
1. **Multiple Spaces**: Create 2-3 spaces for redundancy
2. **Custom URL**: Add all space URLs to env (fallback system)
3. **Monitor**: Check HF dashboard for usage stats
4. **Updates**: Update app.py and docker will rebuild automatically
---
## π Success Checklist
- [ ] Created Hugging Face Space with Docker SDK
- [ ] Uploaded all 3 files (Dockerfile, app.py, requirements.txt)
- [ ] Space built successfully (check logs)
- [ ] Health check returns `{"status": "healthy"}`
- [ ] Test conversion works with curl
- [ ] Added `DOC_CONVERSION_API_URL` to Vercel env
- [ ] Redeployed Vercel site
- [ ] Tested on live site - Word to PDF works!
---
**Need Help?** Check the full [README.md](./README.md) in python-doc-convert folder
|