Flask API for sentiment classification using Hugging Face's fine-tuned model.
- Docker
- Python 3.8 or higher
-
Clone the repository:
git clone https://github.com/pachecowillians/Finetuned-Model-API.git cd Finetuned-Model-API
-
Run the API:
docker-compose up --build
The API will be available at http://localhost:5000/api/classify.
-
Train the Model:
python training/finetune_model.py
To run tests with Docker, make sure the Docker container is running. Then, execute the following command:
docker exec -it finetuned-model-api pytest app/tests
To run tests locally without Docker, follow these steps:
-
Install the required dependencies:
pip install -r requirements.txt
-
Make sure the API is not running locally on port 5000.
-
Execute the following command to run the tests:
pytest app/tests
This will run the tests using pytest
locally.
Endpoint:
POST /api/classify
Request:
{
"text": "This is a positive example."
}
Response:
{
"text": "This is a positive example.",
"predicted_class": "positive",
"class_probabilities": [0.013937118053436756, 0.9860628843307495]
}
- Flask - Web framework
- Hugging Face Transformers - Natural language processing library