Testing & Validation
Testing & Validation
To ensure that Udility Diffuser is correctly configured and generating high-quality educational illustrations, follow the validation steps outlined below.
Prerequisites for Testing
Before running any tests, verify that your environment is properly configured:
- API Connectivity: Ensure you have a valid OpenRouter API key.
- Environment Variable: The key must be exported as
OPENROUTER_API_KEY. - Dependencies: Verify that
cairosvgandmatplotlibare installed, as these are required for rendering and displaying the output.
Running the Notebook Tests
The quickest way to validate the installation is via the provided Google Colab Notebook.
- Open the notebook in your browser.
- Insert your
OPENROUTER_API_KEYin the setup cell. - Run the "Usage Examples" cells to verify the end-to-end pipeline (Text → SVG → PNG).
Manual Functional Validation
You can perform a quick smoke test by running a Python script to generate a basic geometric illustration. This validates that the Llama-3.5 model is responding and the SVG conversion engine is operational.
from Udility import diffuser
# Test: Generate a simple scientific diagram
try:
diffuser.generate_image_from_text(
"A simple diagram showing a right-angled triangle with labels a, b, and c.",
output_filename="test_validation.png"
)
print("Validation Successful: Image generated and saved.")
except Exception as e:
print(f"Validation Failed: {e}")
Validating Output Quality
Since Udility Diffuser is designed for educational and illustrative purposes, validation should focus on the following criteria:
- File Integrity: Confirm that
output.pngis created in your working directory and is not a 0-byte file. - Label Legibility: Open the generated PNG to ensure that text labels (generated via SVG
<text>tags) are legible and correctly positioned. - SVG-to-PNG Accuracy: Ensure the image contains distinct shapes and colors as requested in the prompt. If the image is blank or corrupted, check if
cairosvgdependencies (likelibcairo) are missing from your system. - Educational Context: Verify that the "Text-Based Contexting" has correctly interpreted scientific or mathematical concepts (e.g., verifying that a "distance vs. displacement" graph correctly illustrates the two different paths).
Common Validation Errors
| Error | Cause | Resolution |
| :--- | :--- | :--- |
| EnvironmentError | Missing API Key | Run os.environ['OPENROUTER_API_KEY'] = 'your_key' before importing the diffuser. |
| RuntimeError: Failed to convert SVG | cairosvg backend issue | Ensure cairocffi and system-level Cairo libraries are installed. |
| RuntimeError: Failed to get instructions | API timeout or limit | Check your OpenRouter quota and internet connection. |