FotographerZenCtrl

An image-to-image model for putting product images in context

Deploy ZenCtrl behind an API endpoint in seconds.

Example usage

Fotographer's ZenCtrl model is an image-to-image model that takes a clean image of a product with a blank background and generates a realistic scene for the object.

Input
1import requests
2import base64
3import os
4
5def image_file_to_base64(image_path: str) -> str:
6    """Read an image file and return its base64-encoded string."""
7    with open(image_path, "rb") as image_file:
8        return base64.b64encode(image_file.read()).decode("utf-8")
9
10def save_base64_image(base64_string: str, output_path: str):
11    """Decode a base64 string and save it as an image file."""
12    image_data = base64.b64decode(base64_string)
13    with open(output_path, "wb") as f:
14        f.write(image_data)
15    print(f"Image saved to {output_path}")
16
17def main():
18    model_id = "abcd1234"
19    baseten_api_key = os.environ["BASETEN_API_KEY"]
20    image_path = "images/speaker-input.png"
21
22    image_b64 = image_file_to_base64(image_path)
23
24    payload = {
25        "image": image_b64,
26        "prompt": "a speaker, placed on top of a table, in front of a window,with a beautiful rainy mountain forest landscape outside, well built wooden table, wooden window",
27        "steps": 6,
28        "strength": 1.0,
29        "harmonize": False,
30        "offset": 5,
31        "height": 1024,
32        "width": 1024,
33        "delta": 0,
34        "lora_name": "bg_canny_58000_1024"
35    }
36
37    url = f"https://model-{model_id}.api.baseten.co/environments/production/predict"
38    headers = {"Authorization": f"Api-Key {baseten_api_key}"}
39
40    response = requests.post(url, headers=headers, json=payload)
41
42    if response.status_code == 200:
43        result = response.json()
44        print("Generation successful.")
45
46        generated_b64 = result.get("generated_image")
47        if generated_b64:
48            output_path = "images/generated-output.png"
49            with open(output_path, "wb") as f:
50                f.write(base64.b64decode(generated_b64))
51            print(f"Image saved as {output_path}")
52        else:
53            print("No 'generated_image' key found in the response.")
54    else:
55        print(f"Error: HTTP {response.status_code}")
56        print(response.text)
57
58if __name__ == "__main__":
59    main()
JSON output
1{
2    "generated_image": "<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