Spaces:
Sleeping
Sleeping
| 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! | |