image generation

Playground logoPlayground V2 Aesthetic

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

Model details

View repository

Example usage

The model accepts a few main inputs:

  • 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.

  • 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
Preview image

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
Preview image

image generation models

See all
Fotographer AI
Image generation

ZenCtrl

Custom Server - H100
ByteDance logo
Image generation

SDXL Lightning

1.0 - Lightning - A100
Stability AI logo
Image generation

Stable Diffusion 3 Medium

3 - A100

Playground AI models

See all
Playground logo
Image generation

Playground V2 Aesthetic

v2 - A10G

🔥 Trending models