# 🚀 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