| import gradio as gr |
| import tempfile |
| import trimesh |
| from cad import create_bolt |
| from model import parse_input_with_bert |
|
|
| def generate_bolt(prompt): |
| params = parse_input_with_bert(prompt) |
| model = create_bolt(params) |
|
|
| |
| stl_path = tempfile.NamedTemporaryFile(delete=False, suffix=".stl").name |
| cq.exporters.export(model, stl_path, exportType="STL") |
|
|
| |
| mesh = trimesh.load_mesh(stl_path) |
| glb_path = tempfile.NamedTemporaryFile(delete=False, suffix=".glb").name |
| mesh.export(glb_path) |
|
|
| return glb_path, stl_path |
|
|
| iface = gr.Interface( |
| fn=generate_bolt, |
| inputs=gr.Textbox(lines=2, placeholder="e.g. Make a hex M8 bolt with 1.25mm pitch and 30mm shank..."), |
| outputs=[ |
| gr.Model3D(label="3D Preview (GLB)"), |
| gr.File(label="Download STL") |
| ], |
| title="🛠 AI Bolt Generator", |
| description="Describe the bolt you want. The app uses BERT to extract geometry and generate a 3D model." |
| ) |
|
|
| if __name__ == "__main__": |
| iface.launch() |
|
|