This project is a machine learning application that predicts emotions from text input. It consists of a trained model that can classify text into different emotion categories and a FastAPI-based REST API for serving predictions.
The system can identify 8 different emotions from text:
- Joy
- Sadness
- Fear
- Anger
- Surprise
- Neutral
- Disgust
- Shame
├── api/
│ └── main.py # FastAPI application
├── data/
│ └── emotion_dataset_raw.csv # Dataset used for training
├── model/
│ └── Text_emotions_model.pkl # Trained model file
├── notebook/
│ └── Model_training.ipynb # Jupyter notebook with model training process
├── python-version # Python version specification
├── readme.md # This file
└── requirements.txt # Project dependencies
The model was trained on a dataset containing text samples labeled with emotions. The dataset includes 34,792 entries across 8 emotion categories with the following distribution:
- Joy: 11,045 samples
- Sadness: 6,722 samples
- Fear: 5,410 samples
- Anger: 4,297 samples
- Surprise: 4,062 samples
- Neutral: 2,254 samples
- Disgust: 856 samples
- Shame: 146 samples
The model training process is documented in the Jupyter notebook notebook/Model_training.ipynb. The notebook includes:
- Data loading and exploration
- Data preprocessing
- Model training
- Model evaluation
- Model serialization
The API is built using FastAPI and provides endpoints for emotion prediction.
GET /: Health check endpointPOST /predict: Endpoint for emotion prediction
{
"text": "Your text here"
}{
"Emotion": "The predicted emotion"
}The API is deployed on Render and can be accessed at:
https://textemotions-8p94.onrender.com/
You can use this URL in place of localhost in the usage examples below.
- Clone the repository
- Install dependencies:
pip install -r requirements.txt
- Run the API:
The API will be available at http://localhost:8000
cd api python main.py
- seaborn
- neattext
- joblib
- pandas
- scikit-learn
- numpy
- fastapi
- uvicorn
- pydantic
CURL -X POST "http://localhost:8000/predict" -H "Content-Type: application/json" -d '{"text":"I am so happy today!"}'import requests
response = requests.post(
"http://localhost:8000/predict",
json={"text": "I am so happy today!"}
)
print(response.json())