Text-to-image

NLP
text
image
generation
deep learning
Author

Modelex

Published

October 12, 2023

MODELEX text-to-image transformer -v0.1

Model type: Diffusion-based text-to-image generative model

Make sure to upgrade diffusers to >= 0.19.0:

!pip install diffusers --upgrade
zsh:1: command not found: pip

In addition make sure to install transformerssafetensorsaccelerate as well as the invisible watermark:

!pip install invisible_watermark transformers accelerate safetensors
zsh:1: command not found: pip

Install torch:

!pip install torch
zsh:1: command not found: pip

Install io:

!pip install requires.io
zsh:1: command not found: pip

Inference API request:

token: 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

import requests
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
headers = {"Authorization": "Bearer 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"}

Generate image with prompt:

Astronaut riding a horse
def query(payload):
    response = requests.post(API_URL, headers=headers, json=payload)
    return response.content
image_bytes = query({
    "inputs": "Astronaut riding a horse",
})
# You can access the image with PIL.Image for example
import io
from PIL import Image
image = Image.open(io.BytesIO(image_bytes))
image

Garfield on the moon
def query(payload):
    response = requests.post(API_URL, headers=headers, json=payload)
    return response.content
image_bytes = query({
    "inputs": "Garfield on the moon",
})
# You can access the image with PIL.Image for example
import io
from PIL import Image
image = Image.open(io.BytesIO(image_bytes))
image

Minion at the grocery store
def query(payload):
    response = requests.post(API_URL, headers=headers, json=payload)
    return response.content
image_bytes = query({
    "inputs": "Minion at the grocery store",
})
# You can access the image with PIL.Image for example
import io
from PIL import Image
image = Image.open(io.BytesIO(image_bytes))
image