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

 
 
 

Contributors