A small Flask-based web application that detects emotions from images using a pretrained model.
This README explains how to set up, run, and deploy the app that is included in this repository.
Project structure:
EMOTION_DETECTOR/
├── app.py
├── model.py
├── simple_emotion_detector.py
├── emotion_model.joblib
├── templates/
│ └── index.html
├── requirements.txt
├── Procfile
├── runtime.txt
├── app.json
├── link.txt
└── README.md
Key files and folders:
app.py— Flask application (entry point). The app runs by default on port 8000.model.py— wrapper to initialize and use the trained model.simple_emotion_detector.py— model helper / implementation used bymodel.py.emotion_model.joblib— pretrained model (joblib format) used by the app.templates/— HTML templates (containsindex.html).requirements.txt— Python dependencies.Procfile— Heroku-compatible process file (web: gunicorn app:app).
- Python 3.8+ (recommended)
- Install project dependencies:
pip install -r requirements.txtIf you use a virtual environment (recommended):
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtThe application is a Flask app and can be started directly for development or served with Gunicorn for production-like behavior.
- Development (quick run):
python app.pyBy default the app listens on port 8000. Open http://localhost:8000 in your browser.
- Production / Heroku-like (uses
Procfile):
# start with gunicorn (Procfile uses: web: gunicorn app:app)
gunicorn app:appIf deploying to Heroku, the included Procfile already contains the startup command.
- Open the app in your browser (
/route). - Fill name (required) and optionally email.
- Upload an image file (jpg, jpeg, png, bmp, gif).
- Click the analyze button — the app will return the predicted emotion and confidence, plus a breakdown of emotion percentages.
Notes:
app.pyvalidates uploads (allowed extensions and a 16 MB max file size configured).- If the trained model isn't available or initialization fails, the app falls back to a random prediction for demo purposes.
The pretrained model is provided as emotion_model.joblib in the repository root. model.py contains the code that loads this model (via joblib) and exposes a predict_emotion helper used by app.py.
If you retrain or replace the model, keep the same file path or update model.py accordingly.
The app creates a lightweight SQLite database file named emotion_detection.db in the project root. It stores simple user records and prediction results. The DB is created automatically on first run.
-
Heroku: The
Procfileincludesweb: gunicorn app:appso deployment to Heroku is straightforward. Make sure to set any required environment variables (e.g.SECRET_KEY). -
Docker: You can containerize the app yourself (not included here). Use
gunicorn app:appas the container entrypoint.
- If the app prints an import/initialization error for the detector, ensure
emotion_model.joblibexists andrequirements.txtpackages are installed. - File upload errors: ensure the image is of an allowed type and under 16MB.
- Port in use: change the
PORTenvironment variable or edit the port inapp.pyfor local testing.
Small improvements and fixes are welcome. If you change model behavior or public APIs, please update this README accordingly.
Educational / demo project. No explicit license set in this repository — update if you want to apply one.
If you'd like, I can add a short example curl command and a minimal .env.example next.