This is a web-based application that detects emotions from text input using Natural Language Processing (NLP) and Machine Learning. The app processes the input text and predicts the associated emotion, displaying the result along with the prediction confidence.
-
Real-time Emotion Detection: Enter any text and receive instant emotion analysis.
-
Emotion Classes: The app can detect multiple emotions, including:
- Anger 😠
- Disgust 🤮
- Fear 😨😱
- Happiness 🤗
- Joy 😂
- Neutral 😐
- Sadness 😔
- Shame 😳
- Surprise 😮
-
Confidence Score: Provides a confidence score for each emotion prediction.
-
Visualization: Displays a bar chart of the prediction probabilities for each emotion.
-
Usage Monitoring: Track the number of page visits and emotion classification statistics.
- The user types in a sentence or a block of text in the text area provided.
- The system processes the input text and applies a pre-trained machine learning model to predict the emotion.
- The detected emotion, along with an emoji, is displayed, and the confidence score for the prediction is shown.
- The user can see a probability distribution of all possible emotions for the given input.
- All predictions and usage data are recorded for monitoring purposes.
-
Front-end: Streamlit (Python)
-
Back-end: Flask (Python)
-
Back-end: scikit-learn (Machine Learning Model), joblib (Model Persistence)
-
Visualization: Altair for charts, Plotly for pie charts
-
Database (Optional): SQLite (for tracking usage metrics)
To run this application locally, you'll need:
-
Python 3.8+
-
The following Python libraries:
pip install streamlit pandas joblib scikit-learn altair plotly
- Clone the repository:
git clone https://github.com/rdxkeerthi/Emotion-Detection.git
cd Emotion-Detection
pip install -r requirements.txt
- Place the model file
emotion_classifier_pipe_lr.pkl
in the models/ folder.
streamlit run app.py
- The app should now be running on http://localhost:8501. You can visit this URL in your browser to access the application.
- Push your project to a GitHub repository.
- Go to Streamlit Community Cloud.
- Click on New app and link your GitHub repository.
- Choose the branch (usually
main
) and selectapp.py
as the main file. - Click Deploy.
Your app will be live, and you can share the link with others to detect emotions from their text!
The model used for emotion detection is trained using the following steps:
- Dataset: The model is trained on an emotion-labeled text dataset (e.g., tweets, comments, etc.).
- Pipeline: The pre-processing and model training pipeline includes:
- Text Vectorization: Using
TfidfVectorizer
to convert text into feature vectors. - Classifier: Logistic Regression model trained on the processed text.
Model Persistence: The trained model is saved as a
.pkl
file usingjoblib
.
To retrain the model, follow these steps:
- Prepare the dataset.
- Modify and run the train_model.py script (not included here).
- Save the new model as emotion_classifier_pipe_lr.pkl.
The app includes basic analytics for monitoring usage:
- Page Visits: Track how often the app is visited.
- Emotion Predictions: Track the predicted emotions over time.
- Visualization: View usage metrics using bar charts and pie charts.
- Audio-based Emotion Detection: Extend the app to process speech/audio input to detect emotions.
- Multilingual Support: Support for emotion detection in multiple languages.
- Real-time Feedback: Provide users with immediate feedback on their emotional state based on input.
- Advanced Dashboard: Build a dashboard for admins to monitor app usage, prediction statistics, and user engagement.
This project is licensed under the MIT License.
For any queries, feel free to reach out: