Spaces:
Sleeping
Sleeping
A newer version of the Streamlit SDK is available:
1.52.1
Deployment Guide for Hugging Face Spaces
This guide will help you deploy NyayaSpashti to Hugging Face Spaces.
Prerequisites
- A Hugging Face account (sign up here)
- Google Gemini API key (get one here)
- Pre-built indexes (the
storage/folder with Chroma and BM25 indexes)
Step-by-Step Deployment
1. Prepare Your Repository
Make sure your project has:
- ✅
app.pyin the root directory - ✅
requirements.txtwith all dependencies - ✅
README.md(this will be displayed on your Space) - ✅
rag/folder with all RAG modules - ✅
data/pdfs/folder with your PDF files (optional, if you want to rebuild indexes) - ✅
storage/folder with pre-built indexes (recommended)
2. Create a New Space
- Go to Hugging Face Spaces
- Click "Create new Space"
- Fill in the details:
- Space name:
nyaya-spashti(or your preferred name) - SDK: Select "Streamlit"
- Visibility: Choose Public or Private
- Space name:
- Click "Create Space"
3. Upload Your Files
You can upload files in two ways:
Option A: Using Git (Recommended)
Clone your Space repository:
git clone https://huggingface.co/spaces/YOUR_USERNAME/nyaya-spashti cd nyaya-spashtiCopy all your project files:
# Copy all files from your local project cp -r /path/to/NyayaSpashti/* .Commit and push:
git add . git commit -m "Initial deployment" git push
Option B: Using Web Interface
- Go to your Space page
- Click "Files and versions" tab
- Click "Add file" → "Upload files"
- Upload all necessary files and folders
4. Set Up Secrets (API Keys)
- Go to your Space settings (click the gear icon)
- Navigate to "Variables and secrets" tab
- Click "New secret"
- Add the following secrets:
- Name:
GOOGLE_API_KEY - Value: Your Google Gemini API key
- (Optional) Name:
GEMINI_MODEL_NAME - (Optional) Value:
gemini-2.5-flash-lite(or your preferred model)
- Name:
5. Verify Deployment
- Go to your Space page
- The app should automatically build and deploy
- Wait for the build to complete (check the "Logs" tab if there are issues)
- Once deployed, test the application
Important Notes
Storage Considerations
- Pre-built indexes: Upload your
storage/folder with pre-built Chroma and BM25 indexes - File size limits: Hugging Face Spaces has file size limits. If your indexes are too large:
- Consider using Git LFS for large files
- Or rebuild indexes on first run (slower but works)
Environment Variables
The app automatically reads environment variables set in HF Spaces secrets:
GOOGLE_API_KEY- RequiredGEMINI_MODEL_NAME- Optional (defaults togemini-2.5-flash-lite)
Paths
The app uses relative paths that work in HF Spaces:
data/pdfs/- PDF files directorystorage/- Index storage directory
Building Indexes on HF Spaces
If you need to rebuild indexes on HF Spaces:
- Make sure
data/pdfs/folder contains all PDF files - The app will automatically load existing indexes if available
- Note: Building indexes on HF Spaces may take time and consume resources
Troubleshooting
Build Fails
- Check the "Logs" tab for error messages
- Verify all dependencies are in
requirements.txt - Ensure
app.pyis in the root directory
API Key Issues
- Verify the secret is named exactly
GOOGLE_API_KEY - Check that the API key is valid and has proper permissions
- Ensure the secret is set in Space settings, not in code
Index Loading Errors
- Verify
storage/folder is uploaded correctly - Check that Chroma and BM25 indexes exist
- If indexes are missing, you may need to rebuild them
Memory Issues
- HF Spaces have memory limits
- If you encounter OOM errors, consider:
- Using smaller batch sizes
- Optimizing model loading
- Using a Space with more resources (upgrade if needed)
Updating Your Space
To update your deployed Space:
- Make changes to your local files
- Commit and push to your Space repository:
git add . git commit -m "Update description" git push - HF Spaces will automatically rebuild and redeploy
Support
For issues or questions:
- Check HF Spaces documentation
- Review the app logs in the "Logs" tab
- Check GitHub issues (if applicable)