Skip to content

PankajKumar-11/Emotion-Detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

20 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ˜ƒ Emotion Detection from Text (Machine Learning + Flask App)

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


Emotion UI


πŸ“Œ Project Features

πŸ§ͺ Machine Learning Notebook (Emotion-Detection.ipynb)

  • 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

🌐 Flask Web App (app.py)

  • Input a sentence on the web
  • Backend uses saved model and vectorizer
  • Real-time emotion prediction

πŸ“ Project Structure

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)



πŸš€ How to Run the Project

πŸ”§ 1. Install Required Packages

pip install -r requirements.txt

If you don’t have requirements.txt, manually install:

pip install flask scikit-learn nltk
import nltk
nltk.download('stopwords')

🧠 2. Train and Export the Model (from Notebook)

  1. Open Emotion-Detection.ipynb in Jupyter Notebook

  2. Run the notebook cells step-by-step

  3. At the end, it will generate:

  • emotion_model.pkl

  • vectorizer.pkl


🌐 3. Run the Web App (From Terminal)

python app.py

Then go to: πŸ‘‰ http://127.0.0.1:5000 in your browser Type in a sentence and see its predicted emotion in real-time.


πŸ“Š Sample Prediction

Input: "I feel so lonely and tired today."
Output: Predicted Emotion: sad

Web UI


πŸ“„ License

This project is open-source and available under the MIT License.


πŸ™‹β€β™‚οΈ Author

Pankaj Kumar
GitHub: @PankajKumar-11

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published