context-Classifier2 / DEPLOY.md
parthraninga's picture
Upload 9 files
2afd81c verified

πŸš€ Hugging Face Spaces Deployment Guide

Quick Deploy Steps

1. Create Your Space

  1. Go to huggingface.co/new-space
  2. Name: content-classifier (or your preferred name)
  3. SDK: Docker
  4. Visibility: Public/Private (your choice)
  5. Click Create Space

2. Upload Files

Upload these files to your Space:

Required Files:

  • contextClassifier.onnx (your model file)
  • app.py
  • requirements.txt
  • Dockerfile
  • README.md

Optional Files:

  • test_api.py (for testing)

3. Model File

⚠️ Important: Make sure your contextClassifier.onnx file is in the same directory as these files before uploading.

4. Git Method (Recommended)

# Clone your space
git clone https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
cd YOUR_SPACE_NAME

# Copy your model file
copy path\to\your\contextClassifier.onnx .

# Copy all project files
copy app.py .
copy requirements.txt .
copy Dockerfile .
copy README.md .

# Add and commit
git add .
git commit -m "πŸ” Add content classifier ONNX model"
git push

5. Monitor Deployment

  1. Check Build Logs: Go to your Space > Logs tab
  2. Wait for Build: Usually takes 2-3 minutes
  3. Check Status: Space will show "Building" β†’ "Running"

6. Test Your Space

Once deployed, your API will be available at:

https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space

API Endpoints:

  • /docs - Interactive documentation
  • /predict - Main prediction endpoint
  • /health - Health check
  • /model-info - Model information

7. Example Usage

import requests

# Replace with your actual Space URL
api_url = "https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space"

response = requests.post(
    f"{api_url}/predict",
    json={"text": "This is a test message for classification"}
)

print(response.json())

Troubleshooting

Common Issues:

Build Fails:

  • Check Logs tab for error details
  • Verify all required files are uploaded
  • Ensure contextClassifier.onnx is present

Model Not Found:

  • Verify contextClassifier.onnx is in root directory
  • Check file name matches exactly (case-sensitive)

API Not Responding:

  • Check if Space is "Running" (not "Building")
  • Try accessing /health endpoint first
  • Check Logs for runtime errors

Memory Issues:

  • ONNX model might be too large
  • Consider model optimization
  • Check Space hardware limits

Success Indicators:

βœ… Space shows "Running" status βœ… /health endpoint returns {"status": "healthy"} βœ… /docs shows interactive API documentation βœ… /predict accepts POST requests and returns expected format

Next Steps

  1. Test thoroughly with various text inputs
  2. Share your Space with the community
  3. Monitor usage in Space analytics
  4. Update model by pushing new contextClassifier.onnx

Your Content Classifier is now live and ready to use! πŸŽ‰