Spaces:
Sleeping
Sleeping
File size: 3,297 Bytes
2afd81c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
---
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
```bash
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
```json
{
"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 threatening
- **`final_confidence`**: Confidence score (0.0 to 1.0)
- **`threat_prediction`**: Raw threat probability
- **`sentiment_analysis`**: Sentiment classification and score
- **`onnx_prediction`**: Raw ONNX model output
- **`models_used`**: List of models used for prediction
- **`raw_predictions`**: Complete prediction data
## π οΈ Local Development
1. **Install dependencies:**
```bash
pip install -r requirements.txt
```
2. **Place your model:**
Ensure `contextClassifier.onnx` is in the project root
3. **Run the API:**
```bash
python app.py
```
4. **Visit:** `http://localhost:7860/docs`
## π³ Docker
```bash
# 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!
|