Predict emotional moods from colors, generate palettes, check contrast, and explore color relationships — powered by machine learning.
| Endpoint | Method | Description |
|---|---|---|
/ |
GET |
Health check |
/predict |
POST |
Predict the mood/emotion of a color |
/similar |
POST |
Generate visually similar color variations |
/palette |
POST |
Generate a color palette from a base color |
/contrast |
POST |
Check contrast ratio between two colors |
git clone https://github.com/gggff123/color-api.git
cd color-apipip install -r requirements.txtuvicorn main:app --reloadThe API will be live at http://localhost:8000
Returns a simple health check message.
Response
{
"message": "Color Mood ML API running 🎨"
}Predicts the emotional mood associated with a hex color using a KNN classifier.
Request Body
{
"hex": "#FF0000"
}Response
{
"color": "#FF0000",
"rgb": [255, 0, 0],
"mood": "energetic",
"confidence": 1.0
}Mood Labels
| Color Family | Mood |
|---|---|
| 🔴 Red | energetic |
| 🟢 Green | calm |
| 🔵 Blue | trust |
| 🟡 Yellow | happy |
| 🟣 Purple | creative |
| 🟠 Orange | excited |
| 🩵 Cyan | refreshing |
| 🩷 Pink | romantic |
Returns 5 color variations close to the input color.
Request Body
{
"hex": "#3A7BD5"
}Response
{
"base_color": "#3A7BD5",
"similar_colors": ["#2f6fcb", "#4585d9", "#3370c2", "#4180d8", "#376ed0"]
}Generates a 5-color palette inspired by the input color.
Request Body
{
"hex": "#8E44AD"
}Response
{
"base_color": "#8E44AD",
"palette": ["#a35bc4", "#7230a1", "#b468d8", "#6e2d9f", "#9a4fba"]
}Checks the contrast between two colors and returns a rating.
Request Body
{
"color1": "#FFFFFF",
"color2": "#000000"
}Response
{
"color1": "#FFFFFF",
"color2": "#000000",
"contrast_score": 441.67,
"rating": "excellent"
}Contrast Ratings
| Score | Rating |
|---|---|
| > 200 | excellent |
| 120 – 200 | good |
| < 120 | low |
- FastAPI — Modern async web framework
- scikit-learn — KNN-based mood classification
- NumPy — Color math and vector operations
- Uvicorn — ASGI server
color-mood-ml-api/
├── main.py # FastAPI application & ML model
├── requirements.txt # Python dependencies
└── README.md # You are here
Once running, visit the auto-generated docs:
- Swagger UI → http://localhost:8000/docs
- ReDoc → http://localhost:8000/redoc
MIT © 2024