Spaces:
Sleeping
Sleeping
Hugging Face Spaces Deployment Guide
This guide will walk you through deploying your FastAPI Search Engine to Hugging Face Spaces.
Prerequisites
- A Hugging Face account (sign up at https://huggingface.co/join)
- Git installed on your computer
- Your application files ready
Deployment Steps
Option 1: Deploy via Web Interface (Easiest)
Step 1: Create a New Space
- Go to https://huggingface.co/spaces
- Click on "Create new Space" button
- Fill in the details:
- Space name:
simple-search-engine(or your preferred name) - License: Choose appropriate license (e.g., MIT, Apache 2.0)
- Select the SDK: Choose Docker
- Space hardware: Start with CPU basic (free tier)
- Visibility: Public or Private (your choice)
- Space name:
- Click "Create Space"
Step 2: Upload Files
After creating the Space, you'll see options to upload files:
Upload the following files in this exact order:
README.md(the one provided)Dockerfile(the one provided)requirements.txt(your existing file)main.py(your existing file).gitignore(optional, the one provided)
Click "Commit to main" after uploading each file
Step 3: Wait for Build
- After uploading all files, Hugging Face will automatically start building your Space
- You'll see build logs in the interface
- The build process typically takes 3-5 minutes
- Once complete, your app will be live at:
https://huggingface.co/spaces/YOUR-USERNAME/simple-search-engine
Option 2: Deploy via Git (Recommended for developers)
Step 1: Create Space on Hugging Face
- Go to https://huggingface.co/spaces
- Click "Create new Space"
- Configure as described in Option 1, Step 1
- After creation, copy the Git clone URL (shown on the Space page)
Step 2: Clone the Repository
Open your terminal and run:
# Clone the Space repository
git clone https://huggingface.co/spaces/YOUR-USERNAME/simple-search-engine
cd simple-search-engine
Step 3: Add Your Files
# Copy your files to the cloned directory
# Assuming you're in the simple-search-engine directory
# Copy files
cp /path/to/your/main.py .
cp /path/to/your/requirements.txt .
cp /path/to/provided/Dockerfile .
cp /path/to/provided/README.md .
cp /path/to/provided/.gitignore .
Step 4: Git Add, Commit, and Push
# Configure git LFS (if not already done)
git lfs install
# Add all files
git add .
# Commit changes
git commit -m "Initial deployment of search engine"
# Push to Hugging Face
git push
Step 5: Monitor Deployment
- Go to your Space URL:
https://huggingface.co/spaces/YOUR-USERNAME/simple-search-engine - Watch the build logs
- Once built, your app will be live!
Post-Deployment
Testing Your Deployed App
- Navigate to your Space URL
- You should see the purple gradient search interface
- Try sample queries like:
- "machine learning AI"
- "cloud services AWS"
- "financial revenue"
Monitoring
- Check the Logs tab in your Space to see application logs
- Monitor build status and errors
- View usage statistics
Updating Your App
When you need to update:
Via Web Interface:
- Go to your Space β Files tab
- Click on the file you want to edit
- Make changes
- Commit changes
- Space will rebuild automatically
Via Git:
# Make changes to your files
git add .
git commit -m "Description of changes"
git push
Troubleshooting
Build Fails
Issue: Docker build fails
- Solution: Check the build logs for specific errors
- Common causes:
- Missing dependencies in requirements.txt
- Syntax errors in code
- Port configuration issues
App Not Loading
Issue: Space built successfully but app doesn't load
- Solution:
- Ensure port 7860 is used (required by HF Spaces)
- Check application logs for runtime errors
- Verify NLTK downloads completed successfully
Slow Model Loading
Issue: First request takes a long time
- Solution: This is normal - the SBERT model loads on first request
- The model stays in memory for subsequent requests
- Consider upgrading to better hardware for faster cold starts
Out of Memory
Issue: App crashes with memory errors
- Solution:
- Upgrade to a better hardware tier (CPU upgrade or small GPU)
- Go to Settings β Change hardware
- Note: GPU tiers are paid
Upgrading Hardware
If you need better performance:
- Go to your Space β Settings
- Scroll to "Space hardware"
- Choose from available options:
- CPU basic (Free)
- CPU upgrade (Paid)
- T4 small (GPU, Paid)
- T4 medium (GPU, Paid)
- Click "Save"
Making Your Space Private
- Go to Space β Settings
- Find "Visibility" section
- Change from "Public" to "Private"
- Only you can access the Space when private
Additional Resources
- Hugging Face Spaces Documentation
- Docker Spaces Guide
- Sentence Transformers Documentation
- FastAPI Documentation
Quick Reference: File Structure
Your final file structure should look like:
simple-search-engine/
βββ .gitignore
βββ Dockerfile
βββ README.md
βββ main.py
βββ requirements.txt
Support
If you encounter issues:
- Check the build logs in your Space
- Review the troubleshooting section above
- Ask in Hugging Face Discord or Forums
- Open an issue on Hugging Face Spaces GitHub
Good luck with your deployment! π