Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add client docs for using fully managed sdxl endpoint #27

Merged
merged 6 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
bddppq marked this conversation as resolved.
Show resolved Hide resolved

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
bddppq marked this conversation as resolved.
Show resolved Hide resolved
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.