Spaces:
Sleeping
Sleeping
| # π 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 | |