Spaces:
Sleeping
Hugging Face Deployment Guide
Complete step-by-step guide to deploy your RAG chatbot to Hugging Face Spaces via GitHub Actions CI/CD.
π Prerequisites
- GitHub account with repository: https://github.com/Abeshith/RAG
- Hugging Face account (free): https://huggingface.co
- All API keys ready (Groq, MongoDB, Redis, Qdrant)
π Deployment Steps
Step 1: Create Hugging Face Space
Fill in details:
Owner: [Your HF username] Space name: rag-chatbot (or your choice) License: MIT Select SDK: Docker Hardware: CPU basic (free) or upgrade to GPUClick "Create Space"
Important: Copy your Space URL
Example: https://huggingface.co/spaces/YourUsername/rag-chatbotNote down:
- HF_USERNAME: Your Hugging Face username
- HF_SPACE_NAME: The space name (e.g.,
rag-chatbot)
Step 2: Get Hugging Face Access Token
Click "New token"
Fill in:
Name: github-actions-deploy Role: WriteClick "Generate token"
Copy the token (starts with
hf_...) β οΈ Save it immediately - you won't see it again!
Step 3: Add GitHub Secrets
Go to: https://github.com/Abeshith/RAG/settings/secrets/actions
Click "New repository secret" and add these 3 secrets:
Secret 1:
Name: HF_TOKEN Value: [Paste your HF token from Step 2]Secret 2:
Name: HF_USERNAME Value: [Your Hugging Face username]Secret 3:
Name: HF_SPACE_NAME Value: rag-chatbot (or whatever you named it)Verify all 3 secrets are added
Step 4: Add Hugging Face Space Secrets
Your app needs API keys to run. Add them to HF Space:
Go to your Space:
https://huggingface.co/spaces/[username]/[space-name]Click "Settings" tab
Scroll to "Repository secrets"
Add these 5 secrets:
Secret 1: Name: GROQ_API_KEY Value: [Your Groq API key] Secret 2: Name: MONGODB_URI Value: [Your MongoDB connection string] Secret 3: Name: REDIS_URL Value: [Your Redis connection URL] Secret 4: Name: QDRANT_URL Value: [Your Qdrant cluster URL] Secret 5: Name: QDRANT_API_KEY Value: [Your Qdrant API key]Click "Save" for each secret
Step 5: Trigger Deployment
Now everything is configured! Deploy your app:
Option A: Automatic (Push to GitHub)
# Make any small change (or just trigger workflow)
git commit --allow-empty -m "Trigger HF deployment"
git push origin main
Option B: Manual (GitHub UI)
- Go to: https://github.com/Abeshith/RAG/actions
- Click "Deploy to Hugging Face Spaces" workflow
- Click "Run workflow" β "Run workflow"
Step 6: Monitor Deployment
Watch GitHub Actions:
- Go to: https://github.com/Abeshith/RAG/actions
- Click the running workflow
- Monitor progress through 3 stages:
- β Stage 1: Test Application (~2-3 min)
- β Stage 2: Build Docker Image (~3-5 min)
- β Stage 3: Deploy to HF Spaces (~1 min)
Watch Hugging Face Build:
- Go to your Space:
https://huggingface.co/spaces/[username]/[space-name] - Click "Build" tab
- Watch Docker image build (~5-10 min)
- Status will change: Building β Running
- Go to your Space:
Check Application:
- Once status is "Running", click "App" tab
- Your chatbot should load!
- Try uploading a document and chatting
π Troubleshooting
Issue 1: GitHub Actions Fails at "Deploy to HF Spaces"
Solution: Check if all 3 GitHub secrets are set correctly:
- Go to: https://github.com/Abeshith/RAG/settings/secrets/actions
- Verify:
HF_TOKEN,HF_USERNAME,HF_SPACE_NAME
Issue 2: HF Space Shows "Application Error"
Solution: Check if all 5 HF Space secrets are set:
- Go to Space β Settings β Repository secrets
- Verify all API keys are present
Issue 3: App Starts but Database Connection Fails
Solution: Verify your connection strings:
- MongoDB URI should start with
mongodb+srv://ormongodb:// - Redis URL should start with
redis://orrediss:// - Qdrant URL should be the full cluster URL
Issue 4: Docker Build Fails
Solution: Check HF build logs:
- Go to Space β Build tab β View logs
- Common issues: Missing dependencies, syntax errors
π CI/CD Pipeline Stages
Stage 1: Test Application (2-3 min)
- β Checkout code
- β Install Python 3.11
- β Cache dependencies
- β Install requirements
- β Run pytest with coverage
- β Upload test results
Fails if: Tests don't pass
Stage 2: Build Docker Image (3-5 min)
- β Setup Docker Buildx
- β Build image from Dockerfile
- β Test container startup
- β Verify health check
Fails if: Docker build errors or container won't start
Stage 3: Deploy to HF Spaces (1 min)
- β Configure git
- β Verify secrets
- β Push to HF git repository
- β Trigger HF rebuild
Fails if: Secrets missing or HF authentication fails
π― What Happens After Deployment?
- Hugging Face receives your code
- Detects Dockerfile β Starts Docker build
- Builds image with all dependencies (~5-10 min)
- Starts container on port 7860
- Runs health check every 30 seconds
- App is live! At
https://huggingface.co/spaces/[username]/[space-name]
π Future Deployments
Every time you push to main branch:
- GitHub Actions runs automatically
- Tests β Build β Deploy pipeline executes
- HF Space automatically rebuilds
- New version goes live (~10-15 min total)
π Quick Reference
Your GitHub Repo: https://github.com/Abeshith/RAG
GitHub Actions: https://github.com/Abeshith/RAG/actions
GitHub Secrets: https://github.com/Abeshith/RAG/settings/secrets/actions
Your HF Space: https://huggingface.co/spaces/[YOUR_USERNAME]/[YOUR_SPACE_NAME]
HF Space Settings: https://huggingface.co/spaces/[YOUR_USERNAME]/[YOUR_SPACE_NAME]/settings
β Checklist
Before deployment, ensure:
- HF Space created
- HF token generated
- 3 GitHub secrets added (HF_TOKEN, HF_USERNAME, HF_SPACE_NAME)
- 5 HF Space secrets added (all API keys)
- Code pushed to main branch
- GitHub Actions workflow triggered
- HF build completed successfully
- App is accessible and working
π Success!
Once all stages pass and HF shows "Running":
- Visit your Space URL
- Upload a document (PDF/TXT/MD)
- Ask questions about it
- Toggle RAG ON/OFF to compare responses
- Share your Space with others!
Need Help?
- GitHub Actions Logs: https://github.com/Abeshith/RAG/actions
- HF Build Logs: Your Space β Build tab
- HF Community: https://huggingface.co/spaces/HuggingFaceH4/zephyr-chat/discussions