Spaces:
Sleeping
Sleeping
metadata
title: Content Classifier
emoji: π
colorFrom: blue
colorTo: purple
sdk: docker
pinned: false
license: mit
app_port: 7860
π Content Classifier
A powerful FastAPI-based content classification service using ONNX for threat detection and sentiment analysis.
π Features
- Threat Detection: Classify content for potential threats
- Sentiment Analysis: Analyze text sentiment (positive/negative)
- ONNX Runtime: High-performance model inference
- REST API: Easy-to-use HTTP endpoints
- Auto Documentation: Interactive Swagger UI at
/docs - Health Monitoring: Built-in health checks
π‘ API Endpoints
| Endpoint | Method | Description |
|---|---|---|
/predict |
POST | Classify text content |
/health |
GET | Check API health status |
/model-info |
GET | Get model information |
/docs |
GET | Interactive API documentation |
π§ Usage
Example Request
curl -X POST "https://YOUR-SPACE-NAME.hf.space/predict" \
-H "Content-Type: application/json" \
-d '{"text": "This is a sample text to classify"}'
Example Response
{
"is_threat": false,
"final_confidence": 0.75,
"threat_prediction": 0.25,
"sentiment_analysis": {
"label": "POSITIVE",
"score": 0.5
},
"onnx_prediction": {
"threat_probability": 0.25,
"raw_output": [[0.75, 0.25]],
"output_shape": [1, 2]
},
"models_used": ["contextClassifier.onnx"],
"raw_predictions": {
"onnx": {
"threat_probability": 0.25,
"raw_output": [[0.75, 0.25]]
},
"sentiment": {
"label": "POSITIVE",
"score": 0.5
}
}
}
π Response Format
The API returns a structured response with:
is_threat: Boolean indicating if content is threateningfinal_confidence: Confidence score (0.0 to 1.0)threat_prediction: Raw threat probabilitysentiment_analysis: Sentiment classification and scoreonnx_prediction: Raw ONNX model outputmodels_used: List of models used for predictionraw_predictions: Complete prediction data
π οΈ Local Development
Install dependencies:
pip install -r requirements.txtPlace your model: Ensure
contextClassifier.onnxis in the project rootRun the API:
python app.pyVisit:
http://localhost:7860/docs
π³ Docker
# Build
docker build -t content-classifier .
# Run
docker run -p 7860:7860 content-classifier
π Model Requirements
Your contextClassifier.onnx model should:
- Accept text-based inputs
- Return classification predictions
- Be compatible with ONNX Runtime
βοΈ Configuration
Customize the preprocessing and postprocessing functions in app.py based on your specific model requirements.
π Monitoring
- Health Check:
/health- Monitor API status - Model Info:
/model-info- View model details - Logs: Check application logs for debugging
π License
MIT License - feel free to use and modify!