Image-to-3d
0.4 Quick Start Script Turbo Python
import requests
import time

baseUrl = "https://api.csm.ai/"

def sleep(seconds):
    time.sleep(seconds)

headers = {
    'Content-Type': 'application/json',
    'x-api-key': '6bCfF4467bXXXXXX4E6B271BeC5'
}

uploadObj = {
    "image_url": "https://via.placeholder.com/300/09f/fff.png",
    "preview_mesh": "turbo",
    "pixel_alignment": "highest",
    "model_resolution": "high",
    "resolution": "high_poly",
    "diffusion_time_steps": 75,
    "auto_gen_3d": True,
    "topology": "quads",
    "texture_resolution": 2048
}

response = requests.post(f"{baseUrl}image-to-3d-sessions", json=uploadObj, headers=headers)

imageTo3dSession = response.json()['data']

session_code = imageTo3dSession['session_code']

while True:
    sleep(20)
    response = requests.get(f"{baseUrl}image-to-3d-sessions/{session_code}", headers=headers)
    imageTo3dSession = response.json()['data']
    if imageTo3dSession['status'] == 'spin_generate_done':
        break


chosen_spin_id = 0
spinObj = {
    "selected_spin_index": chosen_spin_id,
    "selected_spin": imageTo3dSession['spins'][chosen_spin_id]['image_url']
}

previewResponse = requests.post(f"{baseUrl}image-to-3d-sessions/get-3d/preview/{session_code}", json=spinObj, headers=headers)

imageTo3dSession = previewResponse.json()['data']

previewAndRefineStatusCodes = ['preview_done', 'training_refine', 'refine_done']

sleep(40)

while True:
    sleep(20)
    response = requests.get(f"{baseUrl}image-to-3d-sessions/{session_code}", headers=headers)
    imageTo3dSession = response.json()['data']
    if imageTo3dSession['status'] in previewAndRefineStatusCodes:
        break