Skip to content

Commit

Permalink
Add client docs for using fully managed sdxl endpoint (#27)
Browse files Browse the repository at this point in the history
* Add client docs for using fully managed sdxl endpoint

* Add images and missing imports

* add more images

* add images

* format

* update images
  • Loading branch information
bddppq authored Sep 1, 2023
1 parent bef76ea commit a5cd772
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 2 deletions.
87 changes: 85 additions & 2 deletions advanced/sdxl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,90 @@ There are two ways to access SDXL model:

Lepton provides the SDXL model as a fully managed api endpoints at https://sdxl.lepton.run. Users can easily use the lepton Python client or existing https request tool to generate high resolution realistic images right away.

Creating the client:
```python
from leptonai.client import Client

API_URL = "https://sdxl.lepton.run"
TOKEN = "YOUR_TOKEN_HERE"

c = Client(API_URL, token=TOKEN)
```

Text to Image:
```python
prompt = "A cat launching rocket"
seed = 1234
image_bytes = c.txt2img(prompt=prompt, seed=seed)
with open("txt2img_prompt.png", "wb") as f:
f.write(image_bytes)
```

Text to Image (with refiner):
```python
prompt = "A cat launching rocket"
seed = 1234
image_bytes = c.txt2img(prompt=prompt, seed=seed, use_refiner=True)
with open("txt2img_prompt_refiner.png", "wb") as f:
f.write(image_bytes)
```
<img src="assets/txt2img.png" width=1024>

Inpaint
```python
import base64
import requests

from leptonai.photon import FileParam


img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"
mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"
prompt = "Mickey mouse sitting on a bench"
seed = 2236


# Directly using urls to pass images
image_bytes = c.inpaint(image=img_url, mask_image=mask_url, prompt=prompt, seed=seed)
with open("inpaint_url.png", "wb") as f:
f.write(image_bytes)

# Or use FileParam to send image files:
img_content = requests.get(img_url).content
mask_content = requests.get(mask_url).content
image_bytes = c.inpaint(
image=FileParam(img_content),
mask_image=FileParam(mask_content),
prompt=prompt,
seed=seed,
)
with open("inpaint_file_param.png", "wb") as f:
f.write(image_bytes)

# Or use base64 to encode image files:
img_content = requests.get(img_url).content
mask_content = requests.get(mask_url).content
image_bytes = c.inpaint(
image=base64.b64encode(img_content).decode("ascii"),
mask_image=base64.b64encode(mask_content).decode("ascii"),
prompt=prompt,
seed=seed,
)
with open("inpaint_base64.png", "wb") as f:
f.write(image_bytes)
```
Image:

<img src="assets/image.png" width=512>

Mask:

<img src="assets/mask.png" width=512>

Result:

<img src="assets/inpaint.png" width=1024>

## Dedicated SDXL inference service

If fully managed api does not fit your use case, you can also easily launch a dedicated SDXL model inference service on Lepton platform.
Expand Down Expand Up @@ -47,8 +131,7 @@ Once the inference service is up (either locally or in the cloud), you can use t
```python
from leptonai.client import Client

SERVICE_URL = "https://sdxl.lepton.run" # if use fully managed api
# SERVICE_URL = "http://localhost:8080" # if run locally
SERVICE_URL = "http://localhost:8080" # if run locally
# SERVICE_URL = "DEPLOYMENT URL shown on Lepton Cloud Platform" # if run on the Lepton Cloud Platform

c = Client(SERVICE_URL)
Expand Down
Binary file added advanced/sdxl/assets/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added advanced/sdxl/assets/inpaint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added advanced/sdxl/assets/mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added advanced/sdxl/assets/txt2img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a5cd772

Please sign in to comment.