This Flask API serves as the backend for the RuxaiLab Bachelor's thesis project, providing facial emotion detection capabilities. It processes video input, detects emotions displayed on faces within the video frames, and integrates with Firebase.
- Video Processing: Upload a video file to analyze emotions displayed on faces within the frames.
- Facial Emotion Detection: Utilizes a pre-trained model to analyze emotions in video frames.
- Firebase Integration: User authentication and storage are managed through Firebase, ensuring secure access to the API.
- Logging: Utilizes Python's logging module for informational and error messages.
- Python: 3.12
- Poetry: 1.8.x
- TensorFlow (CPU): 2.18.0
- Keras: 3.3.3
- OpenCV: 4.9.0
- Flask: 3.0.3
- Firebase Admin SDK: 6.5.0
backend/
│ app.py
│ model_loader.py
│ firebase_service.py
│ video_processor.py
│ requirements.txt (gerado só se necessário)
│ .env
└─ models/
git clone https://github.com/your-username/ruxailab-facial-emotion-api.git
https://python-poetry.org/docs/#installation
poetry install
- Open Firebase Console → Storage
- Copy your bucket name (e.g.
project-id.appspot.com) - Add it to your
.envfile:
STORAGE_BUCKET=your-bucket-here
- Go to Firebase Console → Project Settings → Service Accounts
- Select Python
- Click Generate new private key
- Download the JSON file
- Move it to the project root and rename it to:
service-account.json
This file is required for all Firebase Admin SDK operations.
poetry run python -u app.py
- Send a POST request to
/process_videoendpoint with the name of the video file to be analyzed in the request body. - The API will download the video from Firebase Storage, perform emotion analysis, and store the results in Firestore.
- Once the API is running, it automatically detects new videos uploaded to Firebase Storage, processes them to analyze emotions, and uploads the results to Firestore.
- Send a GET request to
/testendpoint. - The API will call a Firebase function hosted elsewhere for testing purposes.
- POST /process_video: Initiates emotion analysis on the uploaded video.
- GET /test: Calls a Firebase function for testing purposes.