--- 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!