This repository contains the full source code for MDS11 BiasLens, a final-year project designed to explore and analyze demographic bias (gender, age, race) in AI-generated images. The system is built using a combination of React (frontend), Express.js (API), and FastAPI (model serving), and it integrates with Firebase Storage to manage and serve image data.
The goal of this assignment is to evaluate whether modern image generation models (e.g., InstructPix2Pix, Kandinsky, MagicBrush) demonstrate demographic bias when transforming human portraits into images representing various occupations. This is done by:
MDS11_BiasLens/
β
βββ frontend/ # React frontend for selecting filters, generating images, and viewing bias results
βββ mainEndpoint/ # Node.js Express API that connects frontend to model & bias analysis backend
βββ editingModel/ # FastAPI model server using Hugging Face pipelines (Pix2Pix, Img2Img, MagicBrush)
βββ biasAnalyse/ # (Optional) Bias analysis service (can be run locally or via Render)
β
βββ firebase_key.json # Firebase service account config (DO NOT commit this publicly)
βββ env.js # Configuration for endpoints and environment variables
βββ run_all.sh # β
Main script to install dependencies and start all services
βββ README.md
/config/firebase_key.json)π Firebase Note:
You can set up your own Firebase project and create a service account to generate your ownfirebase_key.json.
Refer to: Firebase Admin Setup Docs
- Go to Firebase Console β Project Settings β Service Accounts
- Click "Generate new private key" and save the JSON file.
- Place it in
./config/firebase_key.json. πΌοΈ Setting Up Image Database on Firebase Storage
To run the system with the correct image pipeline, you must organize your original images in Firebase Cloud Storage using the following structure:
π§ Step-by-Step Guide
- Go to Firebase Console Open your project and navigate to Build β Storage.
- Enable Cloud Storage if not already enabled.
- Inside your Storage, create a folder called: originals/
- Inside the originals/ folder, create 18 subfolders based on combinations of gender, age, and race:
originals/
βββ Female_20-29_Black/
βββ Female_20-29_White/
βββ Female_20-29_EastAsian/
βββ Female_40-49_Black/
βββ Female_40-49_White/
βββ Female_40-49_EastAsian/
βββ Female_60-69_Black/
βββ Female_60-69_White/
βββ Female_60-69_EastAsian/
βββ Male_20-29_Black/
βββ Male_20-29_White/
βββ Male_20-29_EastAsian/
βββ Male_40-49_Black/
βββ Male_40-49_White/
βββ Male_40-49_EastAsian/
βββ Male_60-69_Black/
βββ Male_60-69_White/
βββ Male_60-69_EastAsian/
- Upload image files (.jpg or .png) inside each folder. Recommended size: ~600x600px. π Make sure: β’ Images are publicly readable (or use signed URL logic like the project does). β’ The folder naming matches exactly what the system expects. β’ Each folder contains enough images (β₯10 recommended).
π§ Hugging Face Token: This project uses Hugging Face models (e.g., Pix2Pix, Kandinsky, MagicBrush). To use them, sign up at huggingface.co and get your personal access token. Replace the hardcoded HF_TOKEN in editingModel/main.py with your own token.
- Go to your Hugging Face account β Settings β Access Tokens.
- Create a new token (choose βreadβ access).
- Replace the value in main.py like this: HF_TOKEN = "your_actual_token_here"
π
biasAnalyse/.env
FACEPP_KEY="KM1VUqsN1lQGmtfPLxnsXWfYvQPcteQr"
FACEPP_SECRET="tt010dmrqvZBFDQUINyBq8hKMiBuDZ98"
BASE_TMP=/tmp
π§ Usage:
- Create
.envinside thebiasAnalyse/folder.- Replace the API keys with your own credentials if needed.
- Make sure the
BASE_TMPpath exists and is writable by the app.- These variables are read at runtime by the bias analysis backend.
π Security Tip:
Never commit your.envfiles with real credentials to a public repository. Use.gitignoreto exclude them.
Use the provided script to start everything in development mode:
bash run_all.sh
This will:
You can change the running mode by editing the environment variable in .env.development or .env.production.
For example:
MODE=development # for local testing
MODE=production # for deployment
Update your scripts and backend logic to read from this MODE and adjust behavior accordingly.
firebase_key.json or Hugging Face tokens to public repositories..env.development to store sensitive config for production use.This project is developed as part of Monash University's MDS11 final-year project. All models used are publicly available under their respective licenses.
This repository contains the full source code for MDS11 BiasLens, a final-year project designed to explore and analyze demographic bias (gender, age, race) in AI-generated images. The system is built using a combination of React (frontend), Express.js (API), and FastAPI (model serving), and it integrates with Firebase Storage to manage and serve image data.
The goal of this assignment is to evaluate whether modern image generation models (e.g., InstructPix2Pix, Kandinsky, MagicBrush) demonstrate demographic bias when transforming human portraits into images representing various occupations. This is done by:
MDS11_BiasLens/
β
βββ frontend/ # React frontend for selecting filters, generating images, and viewing bias results
βββ mainEndpoint/ # Node.js Express API that connects frontend to model & bias analysis backend
βββ editingModel/ # FastAPI model server using Hugging Face pipelines (Pix2Pix, Img2Img, MagicBrush)
βββ biasAnalyse/ # (Optional) Bias analysis service (can be run locally or via Render)
β
βββ firebase_key.json # Firebase service account config (DO NOT commit this publicly)
βββ env.js # Configuration for endpoints and environment variables
βββ run_all.sh # β
Main script to install dependencies and start all services
βββ README.md
/config/firebase_key.json)π Firebase Note:
You can set up your own Firebase project and create a service account to generate your ownfirebase_key.json.
Refer to: Firebase Admin Setup Docs
- Go to Firebase Console β Project Settings β Service Accounts
- Click "Generate new private key" and save the JSON file.
- Place it in
./config/firebase_key.json. πΌοΈ Setting Up Image Database on Firebase Storage
To run the system with the correct image pipeline, you must organize your original images in Firebase Cloud Storage using the following structure:
π§ Step-by-Step Guide
- Go to Firebase Console Open your project and navigate to Build β Storage.
- Enable Cloud Storage if not already enabled.
- Inside your Storage, create a folder called: originals/
- Inside the originals/ folder, create 18 subfolders based on combinations of gender, age, and race:
originals/
βββ Female_20-29_Black/
βββ Female_20-29_White/
βββ Female_20-29_EastAsian/
βββ Female_40-49_Black/
βββ Female_40-49_White/
βββ Female_40-49_EastAsian/
βββ Female_60-69_Black/
βββ Female_60-69_White/
βββ Female_60-69_EastAsian/
βββ Male_20-29_Black/
βββ Male_20-29_White/
βββ Male_20-29_EastAsian/
βββ Male_40-49_Black/
βββ Male_40-49_White/
βββ Male_40-49_EastAsian/
βββ Male_60-69_Black/
βββ Male_60-69_White/
βββ Male_60-69_EastAsian/
- Upload image files (.jpg or .png) inside each folder. Recommended size: ~600x600px. π Make sure: β’ Images are publicly readable (or use signed URL logic like the project does). β’ The folder naming matches exactly what the system expects. β’ Each folder contains enough images (β₯10 recommended).
π§ Hugging Face Token: This project uses Hugging Face models (e.g., Pix2Pix, Kandinsky, MagicBrush). To use them, sign up at huggingface.co and get your personal access token. Replace the hardcoded HF_TOKEN in editingModel/main.py with your own token.
- Go to your Hugging Face account β Settings β Access Tokens.
- Create a new token (choose βreadβ access).
- Replace the value in main.py like this: HF_TOKEN = "your_actual_token_here"
π
biasAnalyse/.env
FACEPP_KEY="KM1VUqsN1lQGmtfPLxnsXWfYvQPcteQr"
FACEPP_SECRET="tt010dmrqvZBFDQUINyBq8hKMiBuDZ98"
BASE_TMP=/tmp
π§ Usage:
- Create
.envinside thebiasAnalyse/folder.- Replace the API keys with your own credentials if needed.
- Make sure the
BASE_TMPpath exists and is writable by the app.- These variables are read at runtime by the bias analysis backend.
π Security Tip:
Never commit your.envfiles with real credentials to a public repository. Use.gitignoreto exclude them.
Use the provided script to start everything in development mode:
bash run_all.sh
This will:
You can change the running mode by editing the environment variable in .env.development or .env.production.
For example:
MODE=development # for local testing
MODE=production # for deployment
Update your scripts and backend logic to read from this MODE and adjust behavior accordingly.
firebase_key.json or Hugging Face tokens to public repositories..env.development to store sensitive config for production use.This project is developed as part of Monash University's MDS11 final-year project. All models used are publicly available under their respective licenses.