Google Colab Workflow
Google Colab Workflow
For users who prefer a cloud-based environment without the need for local setup, Udility Diffuser provides an official Google Colab integration. This workflow is ideal for rapid prototyping and educational demonstrations.
1. Launching the Notebook
You can access the pre-configured environment directly via the Colab badge in the repository or by visiting the link below:
2. Environment Setup
Once the notebook is open, initialize the environment by installing the Udility package. Run the following command in the first cell:
!pip install Udility
3. API Configuration
To generate images, you must provide an OpenRouter API key. In Colab, it is recommended to set this as an environment variable to ensure the diffuser module can authenticate correctly.
import os
# Securely set your OpenRouter API Key
os.environ['OPENROUTER_API_KEY'] = 'your_openrouter_api_key_here'
Note: You can obtain a free key from OpenRouter, which provides access to the required Meta Llama models.
4. Running the Diffuser
With the environment configured, you can use the diffuser module to generate and visualize images directly within the Colab output cells.
from Udility import diffuser
# Prompt the model to create a labeled educational graphic
diffuser.generate_image_from_text("A diagram showing the parts of a plant cell.")
API Reference for Colab Users
The primary interface for the workflow is the generate_image_from_text function.
diffuser.generate_image_from_text(text_description, output_filename='output.png')
Generates a labeled illustration based on a text prompt and displays it automatically using matplotlib.
- Parameters:
text_description(str): A detailed description of the image or concept you want to visualize (e.g., "The water cycle").output_filename(str, optional): The filename used to save the generated PNG in the Colab file explorer. Defaults to'output.png'.
- Returns:
- None. The function outputs the image directly to the notebook cell and saves a copy to the local disk.
Troubleshooting Colab Issues
- API Key Error: If you receive an
EnvironmentError, ensure thatos.environ['OPENROUTER_API_KEY']is set before calling anydiffuserfunctions. - Image Rendering: The library uses
cairosvgandPillowfor rendering. These are automatically handled by the package installation, but if images fail to display, ensure the cell output is not cleared or hidden.