https://github.com/rupanjana15/beforreal-backend
A FastAPI-based sarcasm detection API that uses a fine-tuned BERT model to classify text as sarcastic or not, with a sarcasm probability score.
https://github.com/rupanjana15/beforreal-backend
api bert docker fastapi machine-learning nlp python sarcasm-detection text-classification torch transformers
Last synced: 2 months ago
JSON representation
A FastAPI-based sarcasm detection API that uses a fine-tuned BERT model to classify text as sarcastic or not, with a sarcasm probability score.
- Host: GitHub
- URL: https://github.com/rupanjana15/beforreal-backend
- Owner: rupanjana15
- License: mit
- Created: 2024-11-12T14:05:22.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-12T14:26:40.000Z (over 1 year ago)
- Last Synced: 2025-01-23T13:33:57.094Z (over 1 year ago)
- Topics: api, bert, docker, fastapi, machine-learning, nlp, python, sarcasm-detection, text-classification, torch, transformers
- Language: Python
- Homepage: https://beforreal.api-cloud.one/docs
- Size: 47.9 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# beforreal backend 🧐




A FastAPI-based sarcasm detection API using a fine-tuned BERT model to predict sarcasm in text.
## Setup
### 1. Download Model and Tokenizer
Get `model.pt` and `tokenizer.pkl` from the [Releases](https://github.com/yourusername/sarcasm-detection-api/releases) section, and place them in the `src/` directory.
### 2. Run Locally
```bash
pip install -r requirements.txt
uvicorn src.app:app --host 0.0.0.0 --port 8000
```
### 3. Run with Docker
```bash
docker build -t sarcasm-detection-api .
docker run -p 8000:8000 sarcasm-detection-api
```
## Usage
**Endpoint:** `POST /predict`
**Payload:**
```json
{
"sentence": "I just love waiting in traffic all day!"
}
```
**Response:**
```json
{
"prediction": "Sarcastic",
"sarcasm_score": 0.87,
"sarcasm": true
}
```
**Example:**
```bash
curl -X POST "http://localhost:8000/predict" -H "Content-Type: application/json" -d '{"sentence": "Your input here"}'
```
## Testing
```bash
pytest test_api.py
```
## License
[MIT License](./LICENSE)