Quick Start
Installation
Get started by installing the Udility package via pip. Ensure you have Python 3.6 or higher installed.
pip install Udility
System Dependencies
The library uses CairoSVG for image processing. On some systems (like macOS or Linux), you may need to install the Cairo library manually if it's not already present:
- macOS:
brew install cairo - Ubuntu/Debian:
sudo apt-get install libcairo2
Configuration
Udility Diffuser uses OpenRouter to access Meta Llama models. You must provide an API key to authenticate your requests.
Set your OpenRouter API Key as an environment variable in your terminal or within your Python script:
Via Python
import os
os.environ['OPENROUTER_API_KEY'] = 'your_openrouter_api_key_here'
Via Terminal
export OPENROUTER_API_KEY='your_openrouter_api_key_here'
Basic Usage
You can generate a labeled educational illustration in just a few lines of code. The library handles the SVG generation, conversion to PNG, and the final display automatically.
from Udility import diffuser
# Generate and display an educational illustration
prompt = "A diagram showing the layers of the Earth: Crust, Mantle, Outer Core, and Inner Core."
diffuser.generate_image_from_text(prompt, output_filename="earth_layers.png")
What happens under the hood?
- Text Processing: The model interprets your prompt to create SVG layout instructions.
- SVG Scripting: It generates raw SVG code based on those instructions.
- Conversion: The SVG is converted to a high-quality PNG.
- Output: The image is saved to your local directory and displayed using
matplotlib.
API Reference
diffuser.generate_image_from_text()
The primary high-level function for creating illustrations.
| Parameter | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| text_description | str | Required | A detailed description of the image or concept you want to visualize. |
| output_filename | str | 'output.png' | The file path where the generated PNG will be saved. |
Returns: None. (Displays the image via matplotlib.plt and writes the file to disk).
Quick Example: Mathematical Visualization
Udility Diffuser is particularly effective for visualizing abstract mathematical concepts:
from Udility import diffuser
# Visualize the concept of a Sine Wave
diffuser.generate_image_from_text(
"A coordinate plane showing a single period of a sine wave with labels for amplitude and wavelength.",
output_filename="sine_wave.png"
)