Image-to-3d
0.2 Quick Start Script Hd Python

import requests
import time
import json

baseUrl = "http://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": "hd",
    "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", data=json.dumps(uploadObj), headers=headers)

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

session_code = imageTo3dSession['session_code']

# print(imageTo3dSession)
# {
#     error: '',
#     message: 'Created',
#     statusCode: 201,
#     data: {
#       user_id: 'XXXXXXX',
#       session_code: 'SESSION_1713430448_7229295',
#       image_url: 'https://via.placeholder.com/300/09f/fff.png',
#       status: 'training_preview',
#       topology: 'quads',
#       resolution: 'high_poly',
#       source: 'external',
#       diffusion_time_steps: 75,
#       auto_gen_3d: true,
#       preview_mesh: 'hd',
#       model_resolution: 'high',
#       texture_resolution: 2048,
#       pixel_alignment: 'highest',
#       created_at: '2024-04-18T08:54:08.575Z',
#       updated_at: '2024-04-18T08:54:09.095Z'
#     }
#   }

sleep(15*60)

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

print("preview_done", imageTo3dSession)

refineResponse = requests.post(f"{baseUrl}image-to-3d-sessions/get-3d/refine/{session_code}", headers=headers)

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

sleep(40*60)

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

print(imageTo3dSession)

# {
#     _id: 'XXXXXXX',
#     user_id: 'XXXXXXX',
#     session_code: 'SESSION_1713441503_6143414',
#     image_url: 'https://via.placeholder.com/300/09f/fff.png',
#     preview_mesh_url: 'XXXXXXXX',
#     preview_mesh_url_zip: 'XXXXXXXX',
#     preview_mesh_url_glb: 'XXXXXXXXXX',
#     preview_mesh_url_usdz: 'XXXXXXXXXX',
#     preview_mesh_url_fbx: '',
#     status: 'training_refine',
#     topology: 'quads',
#     resolution: 'high_poly',
#     source: 'external',
#     auto_gen_3d: true,
#     model_version: '2.0-turbo',
#     selected_spin: 'XXXXXXXX',
#     is_deleted: false,
#     manual_segmentation: false,
#     preview_mesh: 'hd',
#     pixel_alignment: 'highest',
#     model_resolution: 'high',
#     diffusion_time_steps: 75,
#     selected_spin_index: 0,
#     spins: [
     
#     ],
#     created_at: '2024-04-18T11:58:25.287Z',
#     updated_at: '2024-04-18T12:01:03.539Z',
#   }