Qwen Logo

Qwen LogoQwen Image

Ultra-realistic text-to-image model by Qwen

Deploy Qwen Image behind an API endpoint in seconds.

Deploy model

Example usage

The Qwen Image model is a diffusion-based text-to-image model that can generate high-quality images from text prompts. The model outputs a base64 string which can be saved locally.

Input
1import httpx
2import os
3import base64
4from PIL import Image
5from io import BytesIO
6
7# Replace with your model ID and API key
8model_id = "your-model-id"
9baseten_api_key = os.environ["BASETEN_API_KEY"]
10
11def b64_to_pil(b64_str):
12    """Convert base64 string to PIL image"""
13    return Image.open(BytesIO(base64.b64decode(b64_str)))
14
15# Example 1: English prompt
16english_data = {
17    "prompt": "A fashionably dressed man on the streets of New York City holds a sign that says `Qwen Image on Baseten`",
18    "width": 1664,
19    "height": 928,
20    "num_inference_steps": 50,
21    "seed": 42
22}
23
24# Example 2: Chinese prompt
25chinese_data = {
26    "prompt": "一只可爱的小猫坐在花园里,阳光明媚",
27    "width": 1024,
28    "height": 1024,
29    "num_inference_steps": 50
30}
31
32# Call the model with extended timeout for image generation
33print("Generating image... This may take a moment.")
34response = httpx.post(
35    f"https://model-{model_id}.api.baseten.co/development/predict",
36    headers={"Authorization": f"Api-Key {baseten_api_key}"},
37    json=english_data,
38    timeout=httpx.Timeout(120.0)
39)
40
41# Get the result
42result = response.json()
43image_b64 = result.get("data")
44
45# Convert to image and save
46image = b64_to_pil(image_b64)
47image.save("generated_image.jpg")
48print("Image generated successfully! Saved as 'generated_image.jpg'")
JSON output
1{
2    "data": "base64_string"
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