contextClassifier / DEPLOYMENT_GUIDE.md
parthraninga's picture
Upload 8 files
c1f3888 verified
# Hugging Face Spaces Deployment Guide
## Steps to Deploy on Hugging Face Spaces
### 1. Create a New Space
1. Go to [Hugging Face Spaces](https://huggingface.co/new-space)
2. Choose a name for your space (e.g., `content-classifier`)
3. Select **Docker** as the SDK
4. Set the space to **Public** or **Private** as needed
5. Click **Create Space**
### 2. Upload Files to Your Space
You need to upload these files to your Space repository:
```
contextClassifier.onnx # Your ONNX model
app.py # FastAPI application
requirements.txt # Python dependencies
Dockerfile # Docker configuration
README.md # This will become the Space's README
```
### 3. Required Files Content
**For the Space's README.md header, add this at the top:**
```yaml
---
title: Content Classifier
emoji: ๐Ÿ”
colorFrom: blue
colorTo: purple
sdk: docker
pinned: false
license: mit
app_port: 7860
---
```
### 4. Deployment Process
1. **Via Git (Recommended):**
```bash
git clone https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
cd YOUR_SPACE_NAME
# Copy your files
copy contextClassifier.onnx .
copy app.py .
copy requirements.txt .
copy Dockerfile .
# Commit and push
git add .
git commit -m "Add content classifier API"
git push
```
2. **Via Web Interface:**
- Use the **Files** tab in your Space
- Upload each file individually
- Or drag and drop all files at once
### 5. Monitor Deployment
1. Go to your Space URL: `https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME`
2. Check the **Logs** tab to monitor the build process
3. The Space will show "Building" status during deployment
4. Once ready, you'll see the API documentation interface
### 6. Access Your API
Once deployed, your API will be available at:
- **Swagger UI:** `https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/docs`
- **API Endpoints:**
- `POST /predict` - Main prediction endpoint
- `GET /health` - Health check
- `GET /model-info` - Model information
### 7. Example Usage
```python
import requests
# Replace with your actual Space URL
api_url = "https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space"
# Make a prediction
response = requests.post(
f"{api_url}/predict",
json={"text": "This is a test message"}
)
print(response.json())
```
### 8. Important Notes
- **Model Size:** Make sure your `contextClassifier.onnx` file is under the Space's size limit
- **Cold Start:** The first request might take longer as the Space wakes up
- **Logs:** Monitor the logs for any runtime errors
- **Updates:** Any push to the repository will trigger a rebuild
### 9. Troubleshooting
**Common Issues:**
- **Build Fails:** Check logs for dependency issues
- **Model Not Found:** Ensure `contextClassifier.onnx` is in the root directory
- **Port Issues:** Make sure the app uses port 7860
- **Memory Issues:** Large models might exceed memory limits
**Solutions:**
- Review requirements.txt for compatible versions
- Check model file path in app.py
- Verify Dockerfile exposes port 7860
- Consider model optimization for deployment