A wrapper for the leonardo.ai image generation
Project description
Image Generation with Leonardo Library
This document outlines the process of generating images using the Leonardo library in Python, as demonstrated in the provided code snippet.
Overview
The code snippet demonstrates how to use the Leonardo class from the leonardoWrapper module to generate an image based on a textual prompt. The example generates an image of a fantastical scene inside an ancient, otherworldly library.
Steps
-
Initialization: The
Leonardoclass is initialized with a username and password.from leonardoWrapper import Leonardo leonardo = Leonardo(username="your_username", password="your_password")
Note: Replace
your_usernameandyour_passwordwith your actual credentials. -
Creating an Image Generation Request: An image generation request is created with specific parameters such as the prompt, number of images, model ID, model version, image dimensions, and guidance scale.
get_generation_id = leonardo.create_generate_image( prompt="Create a fantastical and visually stunning scene inside an ancient, otherworldly library...", amount_of_images=1, model_id="model_id", sd_version="model_version", # for some models you have to provide the sd_version width=1024, height=768, guidance_scale=7 )
Note: Replace
model_identifierandmodel_versionwith the specific model ID and version you wish to use. For a list of available models and their versions, see models.md. Please note that you can rungen_models_md.pyto update the documentation with the latest model information. -
Waiting for Image Generation: The script waits for the image generation process to complete.
leonardo.wait_for_image_generation(creation_id=get_generation_id)
-
Retrieving the Generated Image: The generated image is retrieved, and its details are printed.
generated_image = leonardo.get_image_generation(creation_id=get_generation_id) print(generated_image) print(generated_image["generated_images"][0]["url"])
Conclusion
This guide introduces the fundamental steps for generating images with the Leonardo library. It encompasses the initialization of the Leonardo class, formulation of an image generation request, supervision of account management throughout the generation phase, and the final retrieval of the created image.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file leonardowrapper-1.1.1.tar.gz.
File metadata
- Download URL: leonardowrapper-1.1.1.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dee4fc55d98ce95d8dccb3828e9d77a1963a42f8cbacd1bebcf2f0e5a52789d4
|
|
| MD5 |
f75bc0852b11a344dc6264c09d417764
|
|
| BLAKE2b-256 |
39e4e7df413e06ce35859d973ed37d53fc37a295278c4b4d2d7a4968775282ae
|
File details
Details for the file leonardoWrapper-1.1.1-py3-none-any.whl.
File metadata
- Download URL: leonardoWrapper-1.1.1-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e86fb6edee26dab3bc2988dc469d5f4fbc7e5c7e50948de9ff95bc9895208be
|
|
| MD5 |
b1b0d82fc7b1f3ee021149b9d9f29944
|
|
| BLAKE2b-256 |
0417e834f3936228568dd78b79b5648c2481707f5a67b22480155129a2e01567
|