Skip to content

Parth-Gupta-github/Face-Expression-Recognition-System

Repository files navigation

Face Expression Recognition

A Streamlit web app that detects faces and predicts facial expressions using a trained CNN model. The app supports both live webcam input and uploaded images.

Features

  • Real-time face expression recognition from webcam feed
  • Image upload mode for static photos
  • Face detection using OpenCV Haar Cascade
  • Emotion classification using a saved Keras model
  • Streamlit-based browser interface

Project Structure

Face-expression-recognition/
+-- app.py
+-- requirements.txt
+-- indices.json
+-- models/
|   +-- basic_cnn_best.keras
+-- Face expression.ipynb
+-- facial_emotion_recognition_using_cnn.ipynb

Emotion Classes

The model predicts one of these emotions:

  • angry
  • disgust
  • fear
  • happy
  • neutral
  • sad
  • surprise

Requirements

  • Python 3.10 or compatible Python version
  • Webcam access for live camera mode
  • A browser for the Streamlit interface

Setup

Open PowerShell in the project folder:

cd "C:\Users\Parth Gupta\Documents\Projects\ML_Project\Face-expression-recognition"

Create a virtual environment if one does not already exist:

python -m venv venv

Activate the virtual environment:

.\venv\Scripts\activate

Install dependencies:

pip install -r requirements.txt

Run the App

Use the virtual environment's Python to run Streamlit:

.\venv\Scripts\python.exe -m streamlit run app.py

Then open the local URL shown in the terminal. It is usually:

http://localhost:8501

Usage

Choose one of the available input modes:

  • Live Camera: starts webcam-based real-time expression recognition.
  • Upload Image: lets you upload a JPG, JPEG, or PNG image and detects expressions in the image.

For live camera mode, allow browser camera permissions if prompted.

Model

The trained model is stored at:

models/basic_cnn_best.keras

The app loads this model automatically when Streamlit starts.

Troubleshooting

ModuleNotFoundError: No module named 'cv2'

Install OpenCV inside the project environment:

.\venv\Scripts\python.exe -m pip install opencv-python

Streamlit uses the wrong Python environment

If streamlit run app.py uses Anaconda or another global Python installation, run it this way instead:

.\venv\Scripts\python.exe -m streamlit run app.py

Webcam does not open

  • Check that no other app is using the camera.
  • Allow camera access in browser and Windows privacy settings.
  • Restart the Streamlit app after changing permissions.

Notebooks

The notebooks in this repository contain training and experimentation work:

  • Face expression.ipynb
  • facial_emotion_recognition_using_cnn.ipynb

About

Facial expression recognition application that detects faces and classifies emotions from live camera input or uploaded images.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors