File size: 4,905 Bytes
a49cd71
 
 
 
 
 
 
 
 
 
8f1f637
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a49cd71
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
---
license: apache-2.0
title: CloneForge
sdk: gradio
emoji: 😻
colorFrom: blue
colorTo: green
short_description: Real-time multimodal object-cloning agent swarm β€” Gemma 4 31
---

# βš’οΈ CloneForge

**Real-time multimodal object-cloning agent swarm β€” Gemma 4 31B on Cerebras.**

Upload or webcam a photo of a physical object; a swarm of specialized agents analyzes it,
plans a fabrication strategy, generates parametric 3D code, **visually critiques its own
result against your photo**, and emits a watertight, 3D-printable STL β€” in seconds, thanks
to Cerebras inference (~1,500+ tok/s).

```
photo(s) ─► πŸ‘ Vision ─► 🧠 Planner ─► πŸ›  Generator ─► πŸ”Ž Visual Critic ─┐
              (specs)     (primitives)   (trimesh code)   (render vs photo) β”‚
                                  β–²                                         β”‚
                                  └──────── fix & regenerate (≀N) β—„β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                   β”‚
                                      watertight STL + 3D preview + quality report
```

## Why it's different
- **The critic has eyes.** After building a mesh we render it (4 views) and send that render
  *back to Gemma alongside the original photo* β€” the model sees the mismatch and issues concrete
  fixes. This render→VLM→fix loop is the main fidelity lever (cf. Query2CAD, CADCodeVerify, LL3M).
- **Watertight by construction.** Output is a composition of parametric primitives
  (box/cylinder/sphere/torus + booleans), so meshes are print-ready with no repair pass β€”
  unlike neural image→3D models (TripoSR/TRELLIS/Hunyuan3D) that need GPUs and produce
  non-manifold draft meshes. It's also **editable**: ask for "20% taller" and it re-runs.
- **Speed is the demo.** A full clone (8–12 agent calls) runs in ~5 s of compute. The
  Speed Race tab shows Cerebras vs OpenAI side-by-side with live TTFT + tok/s.

## Quickstart
```bash
# Python 3.14, uv (python -m venv is unavailable here; uv handles the 3.14 wheels)
uv venv --python 3.14 .venv && . .venv/bin/activate
uv pip install -r requirements.txt

# .env needs:  CEREBRAS_API_KEY=...   OPENAI_API_KEY=...   (OpenAI = fallback + race lane)
python app.py        # open the printed local URL
```

## The app (3 tabs)
- **Clone** β€” photo (upload/webcam) + optional extra views β†’ live agent transcript, mesh render,
  3D preview, downloadable STL. A **Refine** box applies text corrections ("thinner handle")
  reusing the cached analysis.
- **Examples** β€” curated reference objects with **published ground truth** (LEGO 3001, ISO 7089
  washer, DIN 934 nut, 16 mm die, mug, 20-tooth gear). One click clones them and reports
  **dimension match %** and Chamfer/voxel-IoU. Simple parts score high; the gear shows the
  fidelity gap on complex geometry β€” honest by design.
- **Speed Race** β€” same prompt, Cerebras ⚑ vs OpenAI 🐒, live first-token latency + tok/s.

## Architecture
| Module | Role |
|---|---|
| `cloneforge/llm.py` | Unified `AsyncOpenAI` client for **both** providers (Cerebras is OpenAI-compatible); streaming, multi-image input, strict JSON schema, 30-rpm backoff β†’ OpenAI fallback |
| `cloneforge/schemas.py` | Pydantic agent I/O β†’ strict `json_schema` (`strictify`) |
| `cloneforge/agents.py` | Vision Β· Planner Β· Generator Β· **Visual Critic** (zero tool-calling β€” see below) |
| `cloneforge/fabricate.py` | Sandboxed exec of generated code (whitelisted imports) + STL/GLB + watertight validation + stderr self-repair |
| `cloneforge/render.py` | Headless matplotlib 4-view shaded render (no GPU/X11/sudo) |
| `cloneforge/quality.py` | OBB dimension match + Chamfer + voxel-IoU vs ground truth |
| `cloneforge/silhouette.py` | Silhouette-IoU vs the input photo (best-of-N ranking + shape-match score) |
| `cloneforge/orchestrator.py` | Async-generator pipeline (streams to UI) + `refine_pipeline` |
| `cloneforge/examples.py` | Reference library from published part specs |
| `app.py` | Gradio UI |

## Key technical decisions (verified against the live API)
- **Images cannot be combined with tool calling** on Gemma 4 β†’ we use **structured outputs
  everywhere, zero tool calling.**
- **`reasoning_effort` levels are equivalent** on Gemma 4 and *destabilize* structured output
  (empty JSON) β†’ kept **off** on schema'd agents.
- **30 rpm** rate limit β†’ vision is computed once and cached across critic/refine iterations;
  webcam is snapshot-only; 429 β†’ bounded backoff β†’ OpenAI `gpt-5.4-mini` fallback.
- **Python 3.14, no sudo** β†’ CadQuery (≀3.12) and OpenSCAD (apt) are out; **trimesh + manifold3d**
  (pure pip) is the generator, **matplotlib** the renderer.

See [PLAN.md](PLAN.md) for the full build plan and [FIDELITY.md](FIDELITY.md) for the fidelity
analysis, competitive landscape, and roadmap. Demo script: [DEMO.md](DEMO.md).