Skip to content

Commit

Permalink
Merge pull request #12 from wwakabobik/0.0.6
Browse files Browse the repository at this point in the history
0.0.6
  • Loading branch information
wwakabobik authored Oct 14, 2023
2 parents 3c8769a + a11c1f9 commit 2288af8
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 35 deletions.
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,51 @@ This package contains Python API for [Leonardo.ai](https://leonardo.ai/) based o
To install the package, please use package from [pypi](https://pypi.org/project/leonardo-api/):

```bash
pip install leonardo-api
pip install leonardo-api
```

This Python API provides access to Leonardo API using synchronous methods (based on requests library) as well as asynchronous (aiohttp). You can choose one of them - `Leonardo` or `LeonardoAsync`.

To start, you must have paid subscription and create an API access token from you [settings page](https://app.leonardo.ai/settings)->User API. Then, init manager class with using your access_token:

```python
from leonardo_api import Leonardo
leonardo = Leonardo(auth_token='abcd-1234-5678-90ef-deadbeef00000')
from leonardo_api import Leonardo

leonardo = Leonardo(auth_token='abcd-1234-5678-90ef-deadbeef00000')
```

Now you can use all API methods, provided by Leonardo.ai API, i.e. starting getting user info and generating your first image:

```python
response = leonardo.get_user_info() # get your user info
response = leonardo.post_generations(prompt="The quick brown fox jumps over the lazy dog", num_images=1,
negative_prompt='schrodinger cat paradox',
model_id='e316348f-7773-490e-adcd-46757c738eb7', width=1024, height=768,
guidance_scale=7)
response = leonardo.get_user_info() # get your user info
response = leonardo.post_generations(prompt="The quick brown fox jumps over the lazy dog", num_images=1,
negative_prompt='schrodinger cat paradox',
model_id='e316348f-7773-490e-adcd-46757c738eb7', width=1024, height=768,
guidance_scale=7)
```

In according to API reference, you will get the json answer with content about pending job like following:

```json
{'sdGenerationJob': {'generationId': '123456-0987-aaaa-bbbb-01010101010'}}
{"sdGenerationJob": {"generationId": "123456-0987-aaaa-bbbb-01010101010"}}
```

To obtain your image you need to use additional method:

```python

response = leonardo.get_single_generation(generation_id) # get it using response['sdGenerationJob']['generationId']
response = leonardo.get_single_generation(generation_id) # get it using response['sdGenerationJob']['generationId']
```

Or, optionally, you may wait for job completion using following method:

```python
response = leonardo.wait_for_image_generation(generation_id=response['sdGenerationJob']['generationId'])
response = leonardo.wait_for_image_generation(generation_id=response['sdGenerationJob']['generationId'])
```

Finally, you'll get your array of images:

```python
[{'url': 'https://cdn.leonardo.ai/users/abcd-1234-5678-90ef-deadbeef00000/generations/123456-0987-aaaa-bbbb-01010101010/Absolute_Reality_v16_The_quick_brown_fox_jumps_0.jpg', 'nsfw': False, 'id': 'aaaaaa-bbbb-cccc-dddd-ffffffffff', 'likeCount': 0, 'generated_image_variation_generics': []}]
[{'url': 'https://cdn.leonardo.ai/users/abcd-1234-5678-90ef-deadbeef00000/generations/123456-0987-aaaa-bbbb-01010101010/Absolute_Reality_v16_The_quick_brown_fox_jumps_0.jpg', 'nsfw': False, 'id': 'aaaaaa-bbbb-cccc-dddd-ffffffffff', 'likeCount': 0, 'generated_image_variation_generics': []}]
```

![The quick brown fox jumps over the lazy dog](https://raw.githubusercontent.com/wwakabobik/leonardo_api/master/src/assets/fox.jpeg)
Expand All @@ -61,10 +60,10 @@ You'll find descriptions for rest of the methods in official [API reference](htt

---

As option, you may want to use pre-loaded dicts with models (nsfw/community/platform):
As option, you may want to use preloaded dicts with models (nsfw/community/platform):

```python
from leonardo_api import platform_models, custom_models, nsfw_models
from leonardo_api import platform_models, custom_models, nsfw_models
```

Which contains details of models like following:
Expand All @@ -86,3 +85,5 @@ Which contains details of models like following:

Have fun and enjoy!

## Donations
If you like this project, you can support it by donating via [DonationAlerts](https://www.donationalerts.com/r/rocketsciencegeek).
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "leonardo_api"
version = "0.0.5"
version = "0.0.6"
authors = [
{ name="Iliya Vereshchagin", email="[email protected]" },
]
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = leonardo_api
version = attr: leonardo_api.0.0.5
version = attr: leonardo_api.0.0.6
author = Iliya Vereshchagin
author_email = [email protected]
url = https://github.com/wwakabobik/leonardo_api
Expand Down
36 changes: 19 additions & 17 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,51 @@ This package contains Python API for [Leonardo.ai](https://leonardo.ai/) based o
To install the package, please use package from [pypi](https://pypi.org/project/leonardo-api/):

```bash
pip install leonardo-api
pip install leonardo-api
```

This Python API provides access to Leonardo API using synchronous methods (based on requests library) as well as asynchronous (aiohttp). You can choose one of them - `Leonardo` or `LeonardoAsync`.

To start, you must have paid subscription and create an API access token from you [settings page](https://app.leonardo.ai/settings)->User API. Then, init manager class with using your access_token:

```python
from leonardo_api import Leonardo
leonardo = Leonardo(auth_token='abcd-1234-5678-90ef-deadbeef00000')
from leonardo_api import Leonardo

leonardo = Leonardo(auth_token='abcd-1234-5678-90ef-deadbeef00000')
```

Now you can use all API methods, provided by Leonardo.ai API, i.e. starting getting user info and generating your first image:

```python
response = leonardo.get_user_info() # get your user info
response = leonardo.post_generations(prompt="The quick brown fox jumps over the lazy dog", num_images=1,
negative_prompt='schrodinger cat paradox',
model_id='e316348f-7773-490e-adcd-46757c738eb7', width=1024, height=768,
guidance_scale=7)
response = leonardo.get_user_info() # get your user info
response = leonardo.post_generations(prompt="The quick brown fox jumps over the lazy dog", num_images=1,
negative_prompt='schrodinger cat paradox',
model_id='e316348f-7773-490e-adcd-46757c738eb7', width=1024, height=768,
guidance_scale=7)
```

In according to API reference, you will get the json answer with content about pending job like following:

```json
{'sdGenerationJob': {'generationId': '123456-0987-aaaa-bbbb-01010101010'}}
{"sdGenerationJob": {"generationId": "123456-0987-aaaa-bbbb-01010101010"}}
```

To obtain your image you need to use additional method:

```python

response = leonardo.get_single_generation(generation_id) # get it using response['sdGenerationJob']['generationId']
response = leonardo.get_single_generation(generation_id) # get it using response['sdGenerationJob']['generationId']
```

Or, optionally, you may wait for job completion using following method:

```python
response = leonardo.wait_for_image_generation(generation_id=response['sdGenerationJob']['generationId'])
response = leonardo.wait_for_image_generation(generation_id=response['sdGenerationJob']['generationId'])
```

Finally, you'll get your array of images:

```python
[{'url': 'https://cdn.leonardo.ai/users/abcd-1234-5678-90ef-deadbeef00000/generations/123456-0987-aaaa-bbbb-01010101010/Absolute_Reality_v16_The_quick_brown_fox_jumps_0.jpg', 'nsfw': False, 'id': 'aaaaaa-bbbb-cccc-dddd-ffffffffff', 'likeCount': 0, 'generated_image_variation_generics': []}]
[{'url': 'https://cdn.leonardo.ai/users/abcd-1234-5678-90ef-deadbeef00000/generations/123456-0987-aaaa-bbbb-01010101010/Absolute_Reality_v16_The_quick_brown_fox_jumps_0.jpg', 'nsfw': False, 'id': 'aaaaaa-bbbb-cccc-dddd-ffffffffff', 'likeCount': 0, 'generated_image_variation_generics': []}]
```

![The quick brown fox jumps over the lazy dog](https://raw.githubusercontent.com/wwakabobik/leonardo_api/master/src/assets/fox.jpeg)
Expand All @@ -61,10 +60,10 @@ You'll find descriptions for rest of the methods in official [API reference](htt

---

As option, you may want to use pre-loaded dicts with models (nsfw/community/platform):
As option, you may want to use preloaded dicts with models (nsfw/community/platform):

```python
from leonardo_api import platform_models, custom_models, nsfw_models
from leonardo_api import platform_models, custom_models, nsfw_models
```

Which contains details of models like following:
Expand All @@ -84,4 +83,7 @@ Which contains details of models like following:
}
```

Have fun and enjoy!
Have fun and enjoy!

## Donations
If you like this project, you can support it by donating via [DonationAlerts](https://www.donationalerts.com/r/rocketsciencegeek).

0 comments on commit 2288af8

Please sign in to comment.