Skip to content

UdeepChowdary/emotionDetectionLearningSupportEngine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 Emotion Detection & Learning Support Engine

Python Streamlit HuggingFace Gemini SQLite

An AI-powered Streamlit web application that detects a student's emotional state from their study challenge description and delivers personalized, empathetic learning support using BiLSTM, BERT, and Gemini AI.


πŸŽ₯ Video Demonstration

Watch the full live demonstration of the Emotion Detection & Learning Support Engine in action here:
πŸ‘‰ View Project Demo Video


πŸ“ Project Structure

emotion-detection/
β”œβ”€β”€ documentation/                   ← Additional project documentation
β”œβ”€β”€ project files/                   ← Main code & assets directory
β”‚   β”œβ”€β”€ .env                         ← Local environment variables (API keys)
β”‚   β”œβ”€β”€ .venv/                       ← Virtual environment folder
β”‚   β”œβ”€β”€ app.py                       ← Streamlit Web Application entrypoint
β”‚   β”œβ”€β”€ performance_test.py          ← Performance & load testing script
β”‚   β”œβ”€β”€ requirements.txt             ← Project dependencies
β”‚   β”œβ”€β”€ emotion_response_examples.csv ← Saved history (auto-created at runtime)
β”‚   β”œβ”€β”€ emotion_response_mapping.csv  ← Emotion responses (auto-created at runtime)
β”‚   β”œβ”€β”€ data/
β”‚   β”‚   └── emotion_text_dataset.csv  ← Dataset created by Kaggle notebook
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”œβ”€β”€ bltsm/
β”‚   β”‚   β”‚   β”œβ”€β”€ bilstm_student_adaptive.keras
β”‚   β”‚   β”‚   β”œβ”€β”€ tokenizer.pkl
β”‚   β”‚   β”‚   └── label_classes.npy
β”‚   β”‚   └── bert_emotion_model_final/
β”‚   β”‚       β”œβ”€β”€ config.json
β”‚   β”‚       β”œβ”€β”€ model.safetensors
β”‚   β”‚       β”œβ”€β”€ tokenizer.json
β”‚   β”‚       β”œβ”€β”€ tokenizer_config.json
β”‚   β”‚       β”œβ”€β”€ special_tokens_map.json
β”‚   β”‚       └── label_mapping.json
β”‚   β”œβ”€β”€ notebooks/
β”‚   β”‚   └── kaggle_training.ipynb     ← Model training source code
β”‚   └── src/
β”‚       β”œβ”€β”€ __init__.py
β”‚       β”œβ”€β”€ preprocessing.py         ← Text preprocessing & keyword boosting
β”‚       β”œβ”€β”€ model.py                 ← BiLSTM model loader
β”‚       β”œβ”€β”€ bert_model.py            ← BERT model loader
β”‚       └── predict.py               ← Model inference pipeline
β”œβ”€β”€ video demo/                      ← Video demonstration folder
β”‚   └── README.md                    ← Demo video link and summary
β”œβ”€β”€ .gitignore                       ← Git ignore rules
β”œβ”€β”€ LICENSE                          ← Project license
└── README.md                        ← Root documentation file

βš™οΈ Setup Instructions

Important

All project commands must be run from inside the project files folder to ensure relative paths resolve correctly.

Step 1 β€” Get Gemini API Key

  1. Go to Google AI Studio.
  2. Sign in with your Google account.
  3. Click "Get API Key" and then "Create API Key".
  4. Create a .env file inside the project files folder and paste your key:
    GEMINI_API_KEY=your_actual_api_key_here

Step 2 β€” Local Setup (Windows)

Open your terminal at the repository root, then execute:

# Navigate to the project directory
cd "project files"

# Create a virtual environment
python -m venv .venv

# Activate the virtual environment
.venv\Scripts\activate

# Install all required packages
pip install -r requirements.txt

# Download necessary NLTK datasets
python -c "import nltk; nltk.download('stopwords'); nltk.download('punkt'); nltk.download('punkt_tab')"

Step 3 β€” Kaggle Training (GPU Required)

Note

Training models locally is not recommended due to hardware limitations (BERT requires a GPU).

  1. Go to Kaggle.
  2. Create a new Notebook.
  3. Enable GPU T4 x2 accelerator under Settings β†’ Accelerator.
  4. Add the following datasets via the "Add Data" sidebar:
    • google-research-datasets/go_emotions
    • atharvjairath/empatheticdialogues
    • kaggle/isear-dataset
  5. Copy the code blocks from project files/notebooks/kaggle_training.ipynb into your Kaggle cells.
  6. Run the notebook and download the generated output files from /kaggle/working/.
  7. Move the downloaded files to their respective local folders:
    • bilstm_student_adaptive.keras β†’ project files/models/bltsm/
    • tokenizer.pkl β†’ project files/models/bltsm/
    • label_classes.npy β†’ project files/models/bltsm/
    • bert_emotion_model_final/ (entire folder) β†’ project files/models/
    • emotion_text_dataset.csv β†’ project files/data/

Step 4 β€” Run the App

# Ensure you are in the project files directory and venv is active
cd "project files"
streamlit run app.py

Open http://localhost:8501 in your browser.

Step 5 β€” Performance Testing (Optional)

To test the server's load capacity and response times:

  1. Ensure the Streamlit app (app.py) is running.
  2. Open a new terminal, activate the .venv, and run:
    cd "project files"
    python performance_test.py

🎯 Core Features

  • πŸ›‘οΈ Dual-Model Emotion Detection: Leverages a lightweight BiLSTM (for speed and user adaptation) in parallel with a deep BERT model (for semantic nuance).
  • 🎭 5 Target Emotion Classes: Specifically trained on Bored, Confident, Confused, Curious, and Frustrated.
  • πŸ“Š Mixed Emotion Flagging: Detects and highlights mixed emotions if multiple targets score above the $15%$ threshold.
  • ✨ Gemini AI support: Generates highly tailored learning strategies and next steps using the updated Gemini 2.5 Flash model.
  • πŸ“ˆ Live Analytics Dashboard: Track emotion distribution, average confidence over time, and breakdown by academic field.
  • πŸ’Ύ SQLite & CSV Logging: Saves transaction details to SQLite database (app.db) and CSV records for future analysis and training.

πŸ”‘ Technical Specifications

Parameter Value Description
BiLSTM Sequence Length 80 tokens Capped length for text sequences processed by BiLSTM
BERT Sequence Length 128 tokens Maximum context size for BERT inference
Keyword Boost Multiplier 10Γ— Weight multiplier for custom emotional keywords
Mixed Emotion Threshold 15% Minimum score to consider secondary emotions
BERT Class Weights Bored: 1.2
Confident: 1.8
Confused: 0.6
Curious: 1.0
Frustrated: 1.4
Class weights to counteract dataset imbalance during training

⚠️ Edge Cases Handled

  • Missing Models: Provides a friendly Streamlit landing warning if model files are missing, giving exact copy-paste paths.
  • API Key Fallback: If the Gemini API key is missing or invalid, the app silently falls back to hand-crafted templates corresponding to each emotion class.
  • Short Input Protection: Restricts inference on inputs under 3 characters to prevent invalid predictions on empty or short inputs.
  • Auto-created storage: Database files and logging CSVs are safely auto-created at runtime on the first interaction.

About

An AI-powered Streamlit web app that detects a student's emotional state from their study challenge description and delivers personalized, empathetic learning support using BiLSTM, BERT, and Gemini 2.5 Flash AI.

Topics

Resources

License

Stars

2 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors