Playground logoPlayground V2 Aesthetic

A text to image model that generates stylized images from simple text prompts.

Deploy Playground V2 Aesthetic behind an API endpoint in seconds.

Deploy model

Example usage

The model accepts a few main inputs:

  1. prompt: This is text describing the image you want to generate. The output images tend to get better as you add more descriptive words to the prompt.

  2. negative_prompt: Text used to steer the model away from the things you don't want in the output image.

The output JSON object contains a key called output which represents the generated image as a base64 string.

Input
1import requests
2import os
3import base64
4from PIL import Image
5from io import BytesIO
6
7# Replace the empty string with your model id below
8model_id = ""
9baseten_api_key = os.environ["BASETEN_API_KEY"]
10BASE64_PREAMBLE = "data:image/png;base64,"
11
12# Function used to convert a base64 string to a PIL image
13def b64_to_pil(b64_str):
14    return Image.open(BytesIO(base64.b64decode(b64_str.replace(BASE64_PREAMBLE, ""))))
15
16data = {
17  "prompt": "a futuristic motorcycle, vaporwave neon colors, cyberpunk city, detailed, 8K",
18  "negative_prompt": "blurry, low quality",
19  "steps": 30
20}
21
22# Call model endpoint
23res = requests.post(
24    f"https://model-{model_id}.api.baseten.co/production/predict",
25    headers={"Authorization": f"Api-Key {baseten_api_key}"},
26    json=data
27)
28
29# Get output image
30res = res.json()
31output = res.get("output")
32
33# Convert the base64 model output to an image
34img = b64_to_pil(output)
35img.save("output_image.png")
36os.system("open output_image.png")
JSON output
1{
2    "output": "iVBORw0KGgoAAAANSUhEUgAABAAAAAQACAIAAA..."
3}
Preview

Here is another example with a different prompt:

a dreamy landscape with snow capped mountains in the background, clear blue lake in the foreground, surrounded by pine trees

Input
1import requests
2import os
3import base64
4from PIL import Image
5from io import BytesIO
6
7# Replace the empty string with your model id below
8model_id = ""
9baseten_api_key = os.environ["BASETEN_API_KEY"]
10BASE64_PREAMBLE = "data:image/png;base64,"
11
12# Function used to convert a base64 string to a PIL image
13def b64_to_pil(b64_str):
14    return Image.open(BytesIO(base64.b64decode(b64_str.replace(BASE64_PREAMBLE, ""))))
15
16data = {
17  "prompt": "a dreamy landscape with snow capped mountains in the background, clear blue lake in the foreground, surrounded by pine trees",
18  "steps": 40
19}
20
21# Call model endpoint
22res = requests.post(
23    f"https://model-{model_id}.api.baseten.co/production/predict",
24    headers={"Authorization": f"Api-Key {baseten_api_key}"},
25    json=data
26)
27
28# Get output image
29res = res.json()
30output = res.get("output")
31
32# Convert the base64 model output to an image
33img = b64_to_pil(output)
34img.save("output_image.png")
35os.system("open output_image.png")
JSON output
1{
2    "output": "iVBORw0KGgoAAAANSUhEUgAABAAAAAQACAIAAA..."
3}
Preview

Deploy any model in just a few commands

Avoid getting tangled in complex deployment processes. Deploy best-in-class open-source models and take advantage of optimized serving for your own models.

$

truss init -- example stable-diffusion-2-1-base ./my-sd-truss

$

cd ./my-sd-truss

$

export BASETEN_API_KEY=MdNmOCXc.YBtEZD0WFOYKso2A6NEQkRqTe

$

truss push

INFO

Serializing Stable Diffusion 2.1 truss.

INFO

Making contact with Baseten 👋 👽

INFO

🚀 Uploading model to Baseten 🚀

Upload progress: 0% | | 0.00G/2.39G