This project performs emotion classification of text using traditional machine learning models. It includes both:
- A Jupyter Notebook for training, evaluating, and saving the model
- A simple Flask Web App to interactively predict emotions from user input
- Text cleaning and preprocessing (stopwords, punctuation, emojis)
- Keyword extraction per emotion
- Emotion classification using:
- Naive Bayes
- Logistic Regression
- K-Nearest Neighbors (KNN)
- Decision Tree
- WordCloud visualizations
- Model comparison
- Model export as
.pkl
- Input a sentence on the web
- Backend uses saved model and vectorizer
- Real-time emotion prediction
Emotion-Detection-Project/
βββ Emotion-Detection.ipynb (Jupyter notebook for training and evaluation)
βββ app.py (Flask app for interactive prediction)
βββ emotion_model.pkl (Trained ML model (saved from notebook))
βββ vectorizer.pkl (TF-IDF or CountVectorizer)
βββ templates/index.html (Frontend UI for the Flask app)
βββ requirements.txt (Python dependencies)
βββ README.md (This file)
pip install -r requirements.txtIf you donβt have requirements.txt, manually install:
pip install flask scikit-learn nltkimport nltk
nltk.download('stopwords')-
Open
Emotion-Detection.ipynbin Jupyter Notebook -
Run the notebook cells step-by-step
-
At the end, it will generate:
-
emotion_model.pkl -
vectorizer.pkl
python app.pyThen go to:
π http://127.0.0.1:5000 in your browser
Type in a sentence and see its predicted emotion in real-time.
Input: "I feel so lonely and tired today."
Output: Predicted Emotion: sad
This project is open-source and available under the MIT License.
Pankaj Kumar
GitHub: @PankajKumar-11

