π Deploying Devam Jersey Server to Hugging Face Spaces
This guide will help you deploy your jersey similarity detection server to Hugging Face Spaces.
π Prerequisites
- Hugging Face Account: Sign up at huggingface.co
- Git: Ensure git is installed and configured
- Python Environment: Python 3.9+ with pip
π― Quick Start
Option 1: Web Interface (Recommended)
Go to Hugging Face Spaces
- Visit https://huggingface.co/spaces
- Click "Create new Space"
Configure Your Space
- Owner: Your username
- Space name:
devam-jersey-server(or your preferred name) - SDK: Select Docker
- License: Choose appropriate license
- Visibility: Public or Private
- Click "Create Space"
Upload Your Files
- In your new space, click "Files and versions"
- Upload all project files:
inference_server.pyrequirements.txtDockerfileREADME.mdmodels/deepfashion2_yolov8s-seg.ptindex/jersey_metadata.npy- Any other necessary files
Monitor Build
- Go to "Settings" β "Build logs"
- Wait for the Docker build to complete
- Your API will be available at
https://YOUR_USERNAME-devam-jersey-server.hf.space
Option 2: Git Clone Method
Clone the Created Space
git clone https://huggingface.co/spaces/YOUR_USERNAME/devam-jersey-server cd devam-jersey-serverCopy Your Project Files
# Copy all your project files to this directory cp -r /path/to/your/project/* .Commit and Push
git add . git commit -m "Initial upload of Devam Jersey Server" git push
Option 3: CLI Method
Install huggingface_hub
pip install huggingface_hubCreate Space via CLI
huggingface-cli repo create devam-jersey-server --type space --space-sdk dockerClone and Upload
git clone https://huggingface.co/spaces/YOUR_USERNAME/devam-jersey-server cd devam-jersey-server # Copy files and push as in Option 2
π§ Configuration
Environment Variables (Optional)
In your Space settings, you can add environment variables:
MODEL_PATH: Path to your YOLO modelINDEX_PATH: Path to your FAISS indexDEVICE:cudaorcpu
Hardware Requirements
- CPU: Basic CPU is sufficient for testing
- GPU: For production use, consider upgrading to GPU-enabled space
- Memory: At least 4GB RAM recommended
π§ͺ Testing Your Deployment
1. Check Space Status
- Visit your space URL
- Check the "Logs" tab for any errors
- Verify the API is responding
2. Test Endpoints
# Test root endpoint
curl https://YOUR_USERNAME-devam-jersey-server.hf.space/
# Test DINO endpoint (upload an image)
curl -X POST https://YOUR_USERNAME-devam-jersey-server.hf.space/dino \
-F "file=@test_image.jpg"
# Test FAISS endpoint
curl -X POST https://YOUR_USERNAME-devam-jersey-server.hf.space/faiss \
-H "Content-Type: application/json" \
-d '{"features": [0.1, 0.2, ...]}'
3. Use the Test Script
# Update the base_url in test_server.py
python test_server.py
π¨ Troubleshooting
Common Issues
Build Fails
- Check Dockerfile syntax
- Verify all files are uploaded
- Check build logs for specific errors
Model Loading Errors
- Ensure model files are properly uploaded
- Check file paths in code
- Verify model file integrity
Memory Issues
- Consider using smaller models
- Optimize Docker image
- Upgrade to GPU space if needed
API Not Responding
- Check space status
- Verify port configuration (should be 7860)
- Check logs for runtime errors
π³ Docker Build Issues
Package Installation Errors
If you encounter errors like:
Package 'libgl1-mesa-glx' is not available
Solution 1: Use the updated Dockerfile with minimal dependencies Solution 2: Try the alternative Dockerfile:
# Rename the alternative Dockerfile
mv Dockerfile Dockerfile.backup
mv Dockerfile.alternative Dockerfile
git add .
git commit -m "Use alternative Dockerfile for compatibility"
git push
Solution 3: Use a different base image in your Dockerfile:
FROM python:3.9-bullseye
# or
FROM python:3.9-buster
OpenCV Compatibility Issues
If OpenCV fails to install or work:
- The project now uses
opencv-python-headlesswhich is more Docker-friendly - This version doesn't require GUI libraries
Debug Commands
# Check space logs
# Go to Settings β Logs in your HF Space
# Test locally first
python inference_server.py
python test_server.py
# Check Docker build locally
docker build -t devam-jersey .
docker run -p 7860:7860 devam-jersey
π Monitoring
- Build Logs: Check after each push
- Runtime Logs: Monitor for errors during operation
- Space Analytics: Track usage and performance
- API Status: Verify endpoints are responding
π Updates
To update your deployed space:
- Make Changes Locally
- Push to Git
git add . git commit -m "Update description" git push - Monitor Build: Check build logs for success
- Test: Verify changes work as expected
π Additional Resources
π Success!
Once deployed, your jersey similarity server will be available at:
https://YOUR_USERNAME-devam-jersey-server.hf.space
Share this URL with others to use your API!
Need Help? Check the Hugging Face Community for support.