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.
- 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
Face-expression-recognition/
+-- app.py
+-- requirements.txt
+-- indices.json
+-- models/
| +-- basic_cnn_best.keras
+-- Face expression.ipynb
+-- facial_emotion_recognition_using_cnn.ipynb
The model predicts one of these emotions:
- angry
- disgust
- fear
- happy
- neutral
- sad
- surprise
- Python 3.10 or compatible Python version
- Webcam access for live camera mode
- A browser for the Streamlit interface
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 venvActivate the virtual environment:
.\venv\Scripts\activateInstall dependencies:
pip install -r requirements.txtUse the virtual environment's Python to run Streamlit:
.\venv\Scripts\python.exe -m streamlit run app.pyThen open the local URL shown in the terminal. It is usually:
http://localhost:8501
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.
The trained model is stored at:
models/basic_cnn_best.keras
The app loads this model automatically when Streamlit starts.
Install OpenCV inside the project environment:
.\venv\Scripts\python.exe -m pip install opencv-pythonIf 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- 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.
The notebooks in this repository contain training and experimentation work:
Face expression.ipynbfacial_emotion_recognition_using_cnn.ipynb