Spaces:
Runtime error
Runtime error
Hugging Face Spaces Deployment Guide
This guide will help you deploy your HackRx Insurance Policy Assistant to Hugging Face Spaces.
Prerequisites
- A Hugging Face account (free at https://huggingface.co)
- A Google Gemini API key
- Your code pushed to a Git repository (GitHub, GitLab, etc.)
Step 1: Prepare Your Repository
Your repository should contain the following files:
app.py
- Main application entry pointDockerfile
- Docker configurationrequirements.txt
- Python dependenciesparser.py
,embedder.py
,retriever.py
,llm.py
- Application modules.dockerignore
- Docker build optimization
Step 2: Create a Hugging Face Space
- Go to https://huggingface.co/spaces
- Click "Create new Space"
- Choose the following settings:
- Owner: Your username
- Space name:
hackrx-insurance-assistant
(or your preferred name) - Space SDK:
Docker
- License: Choose appropriate license
- Visibility: Public or Private (your choice)
Step 3: Connect Your Repository
- In your new Space, go to the "Settings" tab
- Under "Repository", click "Connect to existing repository"
- Select your Git provider (GitHub, GitLab, etc.)
- Choose your repository
- Click "Connect"
Step 4: Configure Environment Variables
- In your Space settings, go to the "Repository secrets" section
- Add the following secret:
- Name:
GOOGLE_API_KEY
- Value: Your Google Gemini API key
- Name:
Step 5: Deploy
- Push your code to your Git repository
- Hugging Face Spaces will automatically detect the changes and start building
- You can monitor the build progress in the "Logs" tab
- Once built successfully, your API will be available at
https://your-space-name.hf.space
Step 6: Test Your Deployment
Health Check
curl https://your-space-name.hf.space/
Test API Endpoint
curl -X POST https://your-space-name.hf.space/api/v1/hackrx/run \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your_token_here" \
-d '{
"documents": "https://example.com/insurance-policy.pdf",
"questions": ["What is the coverage amount?"]
}'
Troubleshooting
Common Issues
- Build Fails: Check the logs in the "Logs" tab for error messages
- Environment Variable Not Set: Ensure
GOOGLE_API_KEY
is set in Space secrets - Port Issues: The application runs on port 7860 (default for Hugging Face Spaces)
- Memory Issues: If you encounter memory issues, consider optimizing the Dockerfile
Debugging
- Check the build logs in the "Logs" tab
- Monitor the application logs for runtime errors
- Test locally first to ensure everything works
API Documentation
Once deployed, your API will have the following endpoints:
GET /
- Health checkGET /health
- API statusPOST /api/v1/hackrx/run
- Process PDF from URLPOST /api/v1/hackrx/local
- Process local PDF file
Cost Considerations
- Hugging Face Spaces offers free hosting for public spaces
- Private spaces may have usage limits
- Consider the cost of Google Gemini API calls
Security Notes
- Keep your API keys secure
- Use appropriate authentication for production use
- Consider rate limiting for public APIs
Updates
To update your deployment:
- Push changes to your Git repository
- Hugging Face Spaces will automatically rebuild and deploy
- Monitor the build process in the "Logs" tab