138 Downloads Updated 3 months ago
Fine-tuned Gemma 3n model for generating CADQuery Python code from natural language descriptions
C3D-v0 is a specialized language model fine-tuned for generating 3D CAD models through Python code. Built on Googleβs Gemma 3n architecture, this model transforms natural language descriptions into executable CADQuery scripts that can be rendered as 3D models.
This model is part of the C3D project - a complete text-to-CAD pipeline featuring an interactive CLI, 3D web viewer, and local AI inference.
unsloth/gemma-3n-E4B-it# Install the model
ollama pull joshuaokolo/C3Dv0
# Generate CAD code
ollama run joshuaokolo/C3Dv0 "Create a simple gear with 12 teeth"
# Install C3D
npm install -g c3d
# Generate with interactive 3D viewer
c3d generate "a phone case for iPhone 15"
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
# Load model and tokenizer
model_name = "numinousmuses/C3D-v0"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
# Generate CAD code
prompt = "Create a simple rectangular bracket"
inputs = tokenizer(prompt, return_tensors="pt")
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=512,
temperature=0.8,
top_p=0.9,
do_sample=True
)
generated_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(generated_code)
The model works best with direct, descriptive prompts:
"Create a simple gear with 12 teeth"
"Generate a phone case for iPhone 15"
"Make a rectangular bracket with mounting holes"
"Design a simple pulley with a 50mm diameter"
Input: βCreate a simple gear with 12 teethβ
Output:
import cadquery as cq
# Create a gear with 12 teeth
gear = (
cq.Workplane("XY")
.circle(25) # Outer radius
.circle(20) # Inner radius for teeth
.extrude(5) # Thickness
)
# Add teeth around the circumference
for i in range(12):
angle = i * 30 # 360/12 = 30 degrees
tooth = (
cq.Workplane("XY")
.transformed(rotate=(0, 0, angle))
.rect(3, 8)
.extrude(5)
)
gear = gear.union(tooth)
result = gear
@misc{c3d-v0-2024,
title={C3D-v0: AI-Powered CAD Code Generation},
author={Joshua Okolo},
year={2024},
url={https://github.com/unxversal/c3d}
}
This model inherits the license from the base Gemma 3n model. Please refer to the original Gemma license for usage terms.
Contact: Joshua Okolo | Mechanical Engineering + Computer Science @ Harvard | Portfolio