Update README.md
Browse files
README.md
CHANGED
|
@@ -57,7 +57,7 @@ model_path = "gudo7208/CAD-Coder"
|
|
| 57 |
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 58 |
model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype="auto", device_map="auto")
|
| 59 |
|
| 60 |
-
#
|
| 61 |
prompt = """Please create a CadQuery Python code to generate a model based on the following description. The reasoning process MUST BE enclosed within <think> </think> tags. The final CadQuery code MUST BE put in \\boxed{```python
|
| 62 |
code
|
| 63 |
```} with ONLY the executable code inside the box, nothing else.The final model is represented by r.
|
|
@@ -98,40 +98,6 @@ Think step by step, but only keep a minimum draft for each thinking step, with 5
|
|
| 98 |
description:
|
| 99 |
Start by creating a new coordinate system with Euler angles set to zero and a translation vector also set to zero. Next, draw a two-dimensional sketch on the first face. This sketch consists of a single loop made up of four lines. The first line starts at the origin (0.0, 0.0) and ends at (0.6, 0.0). The second line starts at (0.6, 0.0) and ends at (0.6, 0.375). The third line starts at (0.6, 0.375) and ends at (0.0, 0.375). Finally, the fourth line completes the loop by starting at (0.0, 0.375) and ending at the origin (0.0, 0.0). After drawing the sketch, apply a scale factor of 0.6 to the entire sketch. To transform the scaled two-dimensional sketch into a three-dimensional model, extrude the sketch 0.075 units along the normal direction. The final dimensions of the rectangular block are a length of 0.6 units, a width of 0.375 units, and a height of 0.075 units."""
|
| 100 |
|
| 101 |
-
|
| 102 |
-
def extract_code(response):
|
| 103 |
-
"""Extract Python code from response"""
|
| 104 |
-
# Try \boxed{```python ... ```}
|
| 105 |
-
match = re.search(r'\\boxed\{```python\n(.*?)```\}', response, re.DOTALL)
|
| 106 |
-
if match:
|
| 107 |
-
return match.group(1).strip()
|
| 108 |
-
# Try ```python ... ```
|
| 109 |
-
match = re.search(r'```python\n(.*?)```', response, re.DOTALL)
|
| 110 |
-
if match:
|
| 111 |
-
return match.group(1).strip()
|
| 112 |
-
return response
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
def execute_code(code, output_path="output.py"):
|
| 116 |
-
"""Save and execute CadQuery code"""
|
| 117 |
-
with open(output_path, "w", encoding="utf-8") as f:
|
| 118 |
-
f.write(code)
|
| 119 |
-
print(f"Code saved to {output_path}")
|
| 120 |
-
|
| 121 |
-
try:
|
| 122 |
-
exec_globals = {}
|
| 123 |
-
exec(code, exec_globals)
|
| 124 |
-
if 'r' in exec_globals:
|
| 125 |
-
print("Execution SUCCESS! Model 'r' created.")
|
| 126 |
-
return True, exec_globals['r']
|
| 127 |
-
else:
|
| 128 |
-
print("Execution completed but 'r' not found.")
|
| 129 |
-
return False, None
|
| 130 |
-
except Exception as e:
|
| 131 |
-
print(f"Execution FAILED: {e}")
|
| 132 |
-
return False, None
|
| 133 |
-
|
| 134 |
-
|
| 135 |
# Generate
|
| 136 |
text = tokenizer.apply_chat_template(
|
| 137 |
[{"role": "user", "content": prompt}],
|
|
@@ -141,23 +107,7 @@ text = tokenizer.apply_chat_template(
|
|
| 141 |
inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 142 |
outputs = model.generate(**inputs, max_new_tokens=2048)
|
| 143 |
response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
|
| 144 |
-
|
| 145 |
-
print("=" * 50)
|
| 146 |
-
print("Model Response:")
|
| 147 |
-
print("=" * 50)
|
| 148 |
print(response)
|
| 149 |
-
|
| 150 |
-
# Extract and execute
|
| 151 |
-
print("\n" + "=" * 50)
|
| 152 |
-
print("Extracted Code:")
|
| 153 |
-
print("=" * 50)
|
| 154 |
-
code = extract_code(response)
|
| 155 |
-
print(code)
|
| 156 |
-
|
| 157 |
-
print("\n" + "=" * 50)
|
| 158 |
-
print("Execution Result:")
|
| 159 |
-
print("=" * 50)
|
| 160 |
-
success, result = execute_code(code)
|
| 161 |
```
|
| 162 |
|
| 163 |
## Performance
|
|
|
|
| 57 |
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 58 |
model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype="auto", device_map="auto")
|
| 59 |
|
| 60 |
+
# Test data (from the first record in cad_data_test_cot.json)
|
| 61 |
prompt = """Please create a CadQuery Python code to generate a model based on the following description. The reasoning process MUST BE enclosed within <think> </think> tags. The final CadQuery code MUST BE put in \\boxed{```python
|
| 62 |
code
|
| 63 |
```} with ONLY the executable code inside the box, nothing else.The final model is represented by r.
|
|
|
|
| 98 |
description:
|
| 99 |
Start by creating a new coordinate system with Euler angles set to zero and a translation vector also set to zero. Next, draw a two-dimensional sketch on the first face. This sketch consists of a single loop made up of four lines. The first line starts at the origin (0.0, 0.0) and ends at (0.6, 0.0). The second line starts at (0.6, 0.0) and ends at (0.6, 0.375). The third line starts at (0.6, 0.375) and ends at (0.0, 0.375). Finally, the fourth line completes the loop by starting at (0.0, 0.375) and ending at the origin (0.0, 0.0). After drawing the sketch, apply a scale factor of 0.6 to the entire sketch. To transform the scaled two-dimensional sketch into a three-dimensional model, extrude the sketch 0.075 units along the normal direction. The final dimensions of the rectangular block are a length of 0.6 units, a width of 0.375 units, and a height of 0.075 units."""
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
# Generate
|
| 102 |
text = tokenizer.apply_chat_template(
|
| 103 |
[{"role": "user", "content": prompt}],
|
|
|
|
| 107 |
inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 108 |
outputs = model.generate(**inputs, max_new_tokens=2048)
|
| 109 |
response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
print(response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
```
|
| 112 |
|
| 113 |
## Performance
|