Colorizer is a web service that maps natural language text to colors using sentence embeddings. It leverages a pre-trained ONNX model (distiluse-base-multilingual-cased-v2) to generate embeddings, compares them to a set of reference embeddings, and returns the closest color as JSON.
This project demonstrates how to combine ONNX models, Rust, and Actix Web for a lightweight AI-powered API.
- Input any text in multiple languages (thanks to
distiluse-base-multilingual-cased-v2) - Returns the closest reference color as RGB (
r,g,b) - Pre-computed reference embeddings for fast lookup
- Rate-limited API with
actix-governor - Serves static frontend files under
/static
git clone https://github.com/8ria/Colorizer.git
cd ColorizerMake sure you have Rust 1.70+ installed:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shNote: The
models/folder is not included in this repository due to size and licensing. You must download the following files and place them inmodels/:
tokenizer.json— tokenizer fordistiluse-base-multilingual-cased-v2model.onnx— ONNX model converted fromdistiluse-base-multilingual-cased-v2
You can generate embeddings for predefined words (or customize your own):
cargo run --bin generate_ref_embeddingsThis will create custom/ref_embeddings.json.
cargo runThe server will start at http://localhost:8090/.
Request:
{
"text": "sun"
}Response:
{
"r": 255,
"g": 255,
"b": 0
}Serves static/index.html if available. Useful for a simple frontend.
Colorizer/
├─ src/
│ ├─ main.rs # Actix server
│ ├─ bin/
│ │ └─ generate_ref_embeddings.rs # Embedding generator
├─ models/ # ONNX model + tokenizer
├─ custom/ # Generated reference embeddings
├─ static/ # Optional static frontend
├─ Cargo.toml
└─ README.md
actix-web— web frameworkactix-files— static file servingactix-governor— rate limitingort— ONNX Runtime for Rustndarray— numerical arraysserde+serde_json— JSON serializationtokenizers— HuggingFace tokenizers
- The system uses cosine similarity to match input embeddings to reference colors.
- You can easily extend
custom/ref_embeddings.jsonwith more words/colors. - For production deployment, consider HTTPS, caching, and scaling options.
MIT License © AndriaK