zk-rag-image-generator
A plugin for zk-rag that enables image generation using Stable Diffusion 3.5 Medium model.
Description
This plugin provides a tool to generate images from textual descriptions using the Stable Diffusion 3.5 Medium model. It can be used to enhance your RAG (Retrieval-Augmented Generation) applications with image generation capabilities.
Features
- Generate images from textual descriptions
- Save generated images as PNG files
- Integration with mojentic LLM tools
- Comprehensive error handling
- Configurable through a gateway pattern
Installation
pip install zk-rag-image-generator
Usage
The plugin will be automatically discovered by zk-rag when installed. It provides the GenerateImage tool which can be used to create images from textual descriptions.
Example usage through zk-rag:
from zk_rag import get_tool
image_tool = get_tool("generate_image")
filename = image_tool.run(
image_description="A serene mountain landscape at sunset with snow-capped peaks and a clear lake reflecting the orange sky",
base_filename="mountain_sunset"
)
print(f"Image saved as: {filename}") # Will print: Image saved as: mountain_sunset.png
Requirements
- Python >= 3.11
- mojentic (LLM tools framework)
- torch, torchvision, torchaudio (PyTorch stack)
- diffusers (Stable Diffusion implementation)
- transformers (Hugging Face Transformers)
- accelerate (Hardware acceleration support)
- safetensors (Model weight handling)
- Additional dependencies: scipy, protobuf, sentencepiece
For the complete list with specific versions, see requirements.txt.
Local Development
- Clone the repository
- Install dependencies:
pip install -r requirements.txt pip install -r dev-requirements.txt
- Install pre-commit hooks (recommended):
# Create a pre-commit hook that runs pytest cat > .git/hooks/pre-commit << 'EOL' #!/bin/sh # Run pytest echo "Running pytest..." python -m pytest # Store the exit code exit_code=$? # Exit with pytest's exit code exit $exit_code EOL # Make the hook executable chmod +x .git/hooks/pre-commit
Testing Guidelines
- Tests are co-located with implementation files
- Run tests:
pytest - Linting:
flake8 src - Code style:
- Max line length: 127
- Max complexity: 10
- Follow numpy docstring style
Testing Best Practices
- Use pytest for testing, with mocker if you require mocking
- Do not use unittest or MagicMock directly
- Use @fixture markers for pytest fixtures
- Break up fixtures into smaller fixtures if they are too large
- Separate test phases with a single blank line
- Each test must fail for only one clear reason
- Only write mocks for our own gateway classes
License
MIT License
Author
Stacey Vetzal (stacey@vetzal.com)
Metadata
Release files for zk-rag-image-generator 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| zk_rag_image_generator-1.1.0.tar.gz | 4.0 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| zk_rag_image_generator-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.6 kB
Release files / zk_rag_image_generator-1.1.0.tar.gz
| Download URL | zk_rag_image_generator-1.1.0.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6f1f590062aa17a816ef744de96e6a2cfe4d04d00a37a2090e47ed8354f35fd1
|
|
BLAKE2b-256 checksum How to use checksums |
88f1c522dbfe1573f072feeb7c0ecf6e4857ef34181ed3bb2972bf57a0494b71
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 9, 2025.
Transparency logRelease files / zk_rag_image_generator-1.1.0-py3-none-any.whl
| Download URL | zk_rag_image_generator-1.1.0-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2d2236fcdca681fba71db51d8e51e25b4c7687edbe42813896134c02f68faf73
|
|
BLAKE2b-256 checksum How to use checksums |
07c213bc3088524f2efda5624d4da5b54125277ee0445da83b9de0b6a196122f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 9, 2025.
Transparency logSecurity for zk-rag-image-generator 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for zk_rag_image_generator-1.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 9, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.