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.
Watch the full live demonstration of the Emotion Detection & Learning Support Engine in action here:
π View Project Demo Video
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
Important
All project commands must be run from inside the project files folder to ensure relative paths resolve correctly.
- Go to Google AI Studio.
- Sign in with your Google account.
- Click "Get API Key" and then "Create API Key".
- Create a
.envfile inside theproject filesfolder and paste your key:GEMINI_API_KEY=your_actual_api_key_here
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')"Note
Training models locally is not recommended due to hardware limitations (BERT requires a GPU).
- Go to Kaggle.
- Create a new Notebook.
- Enable GPU T4 x2 accelerator under Settings β Accelerator.
- Add the following datasets via the "Add Data" sidebar:
google-research-datasets/go_emotionsatharvjairath/empatheticdialogueskaggle/isear-dataset
- Copy the code blocks from
project files/notebooks/kaggle_training.ipynbinto your Kaggle cells. - Run the notebook and download the generated output files from
/kaggle/working/. - 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/
# Ensure you are in the project files directory and venv is active
cd "project files"
streamlit run app.pyOpen http://localhost:8501 in your browser.
To test the server's load capacity and response times:
- Ensure the Streamlit app (
app.py) is running. - Open a new terminal, activate the
.venv, and run:cd "project files" python performance_test.py
- π‘οΈ 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.
| 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.2Confident: 1.8Confused: 0.6Curious: 1.0Frustrated: 1.4 |
Class weights to counteract dataset imbalance during training |
- 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.