from transformers import Qwen3VLForConditionalGeneration, AutoProcessorfrom datasets import load_datasetfrom PIL import Imageimport io model_name = "ADSKAILab/Zero-To-CAD-Qwen3-VL-2B"model = Qwen3VLForConditionalGeneration.from_pretrained(model_name, torch_dtype="auto", device_map="auto")processor = AutoProcessor.from_pretrained(model_name) # Load 8 rendered views from the datasetds = load_dataset("ADSKAILab/Zero-To-CAD-1m", split="train", streaming=True)sample = next(iter(ds))views = [ Image.open(io.BytesIO(sample[f"image_{i}"])) if isinstance(sample[f"image_{i}"], bytes) else sample[f"image_{i}"] for i in range(8)] # Or load 8 views from local files:# views = [Image.open(f"view_{i}.png") for i in range(8)] messages = [ { "role": "system", "content": "You are a CAD code assistant. Given multiple rendered views of a 3D shape, generate clean, well-structured CadQuery Python code that accurately reproduces the geometry." }, { "role": "user", "content": [ *[{"type": "image", "image": view} for view in views], {"type": "text", "text": "Generate CadQuery code for this shape."} ] }] text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)inputs = processor(text=text, images=views, return_tensors="pt").to(model.device) output_ids = model.generate(**inputs, max_new_tokens=4096)output_text = processor.batch_decode(output_ids[:, inputs.input_ids.shape[1]:], skip_special_tokens=True)[0] print(output_text)