Spaces:
4
Sleeping

Adi12345 commited on
Commit
626c375
·
verified ·
1 Parent(s): 170e1ba

Upload 5 files

Browse files
dvnc_ai_v2_hf/README.md ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: DVNC.AI
3
+ emoji: 🧠
4
+ colorFrom: gray
5
+ colorTo: indigo
6
+ sdk: gradio
7
+ app_file: app.py
8
+ pinned: false
9
+ short_description: Connectome-native scientific discovery workspace for Hugging Face Spaces
10
+ ---
11
+
12
+ # DVNC.AI — Hugging Face Space (Version 2)
13
+
14
+ This package is designed for direct upload to a **Gradio** Hugging Face Space.
15
+
16
+ ## Root files to keep at the top level
17
+ - `app.py`
18
+ - `requirements.txt`
19
+ - `README.md`
20
+ - `core/`
21
+ - `ui/`
22
+ - `assets/`
23
+
24
+ ## What this version adds
25
+ - Claude API wiring scaffold using the Anthropic Python SDK
26
+ - Three.js-based connectome canvas embedded inside the Gradio interface
27
+ - Agent-by-agent expandable trays
28
+ - Candidate cards that flip to show alternative discovery routes
29
+ - A clearer repository structure so you can replace mock orchestration with your production backend
30
+
31
+ ## Hugging Face upload instructions
32
+ If you are uploading manually in the Hugging Face web UI, upload the **contents** of this folder directly into the **root of your Space repository**.
33
+
34
+ That means these paths should exist at the top level of the Space:
35
+ - `app.py`
36
+ - `requirements.txt`
37
+ - `README.md`
38
+ - `core/dvnc_engine.py`
39
+ - `ui/connectome.html`
40
+
41
+ Do **not** upload the zip itself into a nested folder inside the Space. Extract it locally first, then upload the extracted contents to the repository root.[cite:276][cite:292][cite:166]
42
+
43
+ ## Required secret
44
+ In your Hugging Face Space, go to **Settings → Variables and secrets** and add:
45
+ - `ANTHROPIC_API_KEY` = your Claude API key
46
+
47
+ The Anthropic Python SDK reads `ANTHROPIC_API_KEY` from the environment.[cite:294][cite:300]
48
+
49
+ ## How to swap in your real logic
50
+ - Replace `core/dvnc_engine.py` graph mocks with your real query router, KG lookup, and 7-agent orchestration.
51
+ - Keep `app.py` as the Gradio entrypoint expected by Hugging Face Spaces.[cite:276]
52
+
53
+ ## Notes
54
+ This build uses a no-bundle Three.js import-map workflow suitable for a static embedded front-end panel.[cite:297][cite:299]
dvnc_ai_v2_hf/app.py ADDED
@@ -0,0 +1,259 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import pathlib
3
+ import gradio as gr
4
+ from core.dvnc_engine import run_discovery
5
+
6
+ MODELS = ["DVNC Sovereign", "DVNC Atlas", "DVNC Curie"]
7
+
8
+ CONNECTOME_SNIPPET = pathlib.Path("ui/connectome.html").read_text()
9
+
10
+
11
+ def build_models_html(selected):
12
+ data = {
13
+ "DVNC Sovereign": "Maximum depth orchestration",
14
+ "DVNC Atlas": "Balanced research mode",
15
+ "DVNC Curie": "Experimental anomaly mode",
16
+ }
17
+ out = []
18
+ for name, desc in data.items():
19
+ active = "active" if name == selected else ""
20
+ out.append(f'<div class="model-pill {active}"><span>{name}</span><small>{desc}</small></div>')
21
+ return '<div class="model-strip">' + ''.join(out) + '</div>'
22
+
23
+
24
+ def build_chat_html(query, data):
25
+ return f'''
26
+ <div class="chat-panel panel">
27
+ <div class="bubble user"><span class="role">You</span><p>{query}</p></div>
28
+ <div class="bubble ai"><span class="role">DVNC</span><p>{data.get("summary","")}</p></div>
29
+ <div class="bubble system"><span class="role">Primary Hypothesis</span><p>{data.get("primary_hypothesis","")}</p></div>
30
+ </div>
31
+ '''
32
+
33
+
34
+ def build_reasoning_html(steps):
35
+ chunks = []
36
+ for s in steps:
37
+ chunks.append(f'''
38
+ <details class="tray" {'open' if s['step']==1 else ''}>
39
+ <summary><span class="step">{s['step']}</span><div><strong>{s['agent']}</strong><small>{s['tag']}</small></div></summary>
40
+ <div class="tray-body">{s['summary']}</div>
41
+ </details>
42
+ ''')
43
+ return '<div class="panel tray-panel">' + ''.join(chunks) + '</div>'
44
+
45
+
46
+ def build_cards_html(cards):
47
+ html = []
48
+ for c in cards:
49
+ html.append(f'''
50
+ <article class="candidate-card" tabindex="0">
51
+ <div class="candidate-card-inner">
52
+ <div class="candidate-face front">
53
+ <div class="top"><span class="chip">{c['agent']}</span><span class="score">{c['score']}</span></div>
54
+ <h4>{c['title']}</h4>
55
+ <p>{c['front']}</p>
56
+ <div class="meta"><span>Novelty</span><strong>{c['novelty']}</strong></div>
57
+ </div>
58
+ <div class="candidate-face back">
59
+ <div class="top"><span class="chip alt">Alt path</span><span class="score">{c['score']}</span></div>
60
+ <h4>{c['title']}</h4>
61
+ <p>{c['back']}</p>
62
+ <div class="meta"><span>Swap state</span><strong>Ready</strong></div>
63
+ </div>
64
+ </div>
65
+ </article>
66
+ ''')
67
+ return '<div class="panel cards-panel"><div class="candidate-grid">' + ''.join(html) + '</div></div>'
68
+
69
+
70
+ def build_metrics_md(metrics, model_used):
71
+ lines = [f"# Discovery Output\n", f"**Claude model used:** {model_used}\n", "## Metrics"]
72
+ for k, v in metrics.items():
73
+ lines.append(f"- {k}: {v}/100")
74
+ lines.append("\n## Next action\n- Replace `core/dvnc_engine.py` with your production graph and evidence stack.")
75
+ return "\n".join(lines)
76
+
77
+
78
+ def build_frontend_payload(data):
79
+ return f"""
80
+ <script>
81
+ window.__DVNC_GRAPH__ = {json.dumps(data.get('graph', {}))};
82
+ </script>
83
+ {CONNECTOME_SNIPPET}
84
+ """
85
+
86
+
87
+ def run(query, model_name):
88
+ data = run_discovery(query, model_name)
89
+ return (
90
+ build_models_html(model_name),
91
+ build_chat_html(query, data),
92
+ build_frontend_payload(data),
93
+ build_reasoning_html(data.get("reasoning", [])),
94
+ build_cards_html(data.get("cards", [])),
95
+ build_metrics_md(data.get("metrics", {}), data.get("model_used", "unknown")),
96
+ )
97
+
98
+ CSS = r'''
99
+ :root{--bg:#07080c;--panel:#0f131a;--panel2:#131925;--line:rgba(255,255,255,.08);--text:#f7f8fc;--muted:#8e98ab;--gold:#f0cf92;--teal:#8ce7dc;--blue:#7ea6ff;--radius:24px;--shadow:0 25px 80px rgba(0,0,0,.42)}
100
+ html,body,.gradio-container{background:radial-gradient(circle at 15% 0%, rgba(126,166,255,.16), transparent 25%),radial-gradient(circle at 90% 10%, rgba(240,207,146,.12), transparent 20%),linear-gradient(180deg,#05060a,#090b10 60%,#06070b)!important;color:var(--text)!important;font-family:Inter,system-ui,sans-serif}
101
+ .gradio-container{max-width:1550px!important;padding:20px!important} footer{display:none!important}
102
+ #app-shell{border:1px solid var(--line);background:linear-gradient(180deg,rgba(12,14,20,.92),rgba(8,10,14,.94));box-shadow:var(--shadow);border-radius:30px;overflow:hidden}
103
+ #app-shell .grid{display:grid;grid-template-columns:1.04fr .96fr;min-height:88vh}.left,.right{padding:24px}.left{border-right:1px solid var(--line);display:flex;flex-direction:column;gap:18px}.right{display:grid;grid-template-rows:auto auto auto 1fr;gap:18px}
104
+ .hero{display:flex;justify-content:space-between;align-items:center;gap:12px}.brand{display:flex;gap:14px;align-items:center}.logo{width:46px;height:46px;border-radius:15px;display:grid;place-items:center;border:1px solid rgba(255,255,255,.08);background:linear-gradient(135deg,rgba(240,207,146,.22),rgba(140,231,220,.1))}.logo svg{width:25px;height:25px;color:var(--gold)}.brand h1{margin:0;font-size:1.08rem}.brand p{margin:3px 0 0;color:var(--muted);font-size:.86rem}.live{display:flex;gap:10px;align-items:center;color:#cfd8e7}.live i{width:10px;height:10px;border-radius:50%;background:var(--teal);display:inline-block;box-shadow:0 0 18px rgba(140,231,220,.5)}
105
+ .panel{border:1px solid var(--line);background:linear-gradient(180deg,rgba(16,19,28,.9),rgba(11,13,19,.88));border-radius:22px;box-shadow:inset 0 1px 0 rgba(255,255,255,.04)}
106
+ .model-strip{display:grid;grid-template-columns:repeat(3,1fr);gap:12px}.model-pill{padding:14px;border:1px solid var(--line);border-radius:18px;background:rgba(255,255,255,.02);display:flex;flex-direction:column;gap:4px}.model-pill.active{border-color:rgba(240,207,146,.45);background:linear-gradient(135deg,rgba(240,207,146,.14),rgba(255,255,255,.02))}.model-pill span{font-weight:650}.model-pill small{color:var(--muted)}
107
+ .querybox,.querybox>div{background:rgba(255,255,255,.02)!important;border-color:var(--line)!important;border-radius:18px!important}.querybox textarea{color:var(--text)!important}
108
+ .chat-panel{padding:18px;display:flex;flex-direction:column;gap:14px;min-height:360px}.bubble{max-width:86%;padding:16px 18px;border:1px solid var(--line);border-radius:22px}.bubble .role{font-size:.72rem;text-transform:uppercase;letter-spacing:.14em;color:var(--muted)}.bubble p{margin:8px 0 0;line-height:1.6}.bubble.user{margin-left:auto;background:linear-gradient(135deg,rgba(126,166,255,.18),rgba(126,166,255,.08))}.bubble.ai{background:linear-gradient(135deg,rgba(255,255,255,.06),rgba(255,255,255,.03))}.bubble.system{background:linear-gradient(135deg,rgba(240,207,146,.13),rgba(240,207,146,.05))}
109
+ .brain-shell{padding:18px}.brain-head{display:flex;justify-content:space-between;gap:16px;align-items:flex-end;margin-bottom:12px}.eyebrow{margin:0 0 4px;font-size:.72rem;letter-spacing:.16em;text-transform:uppercase;color:var(--gold)}.brain-head h3{margin:0;font-size:1.1rem}.brain-help{color:var(--muted);font-size:.8rem}#dvnc-three-root{height:400px;border-radius:20px;border:1px solid rgba(255,255,255,.05);overflow:hidden;background:radial-gradient(circle at center, rgba(126,166,255,.06), transparent 34%),linear-gradient(180deg,rgba(255,255,255,.02),rgba(255,255,255,.01))}
110
+ .tray-panel{padding:14px;display:flex;flex-direction:column;gap:10px}.tray{border:1px solid var(--line);border-radius:18px;background:rgba(255,255,255,.02);overflow:hidden}.tray summary{list-style:none;display:grid;grid-template-columns:42px 1fr;gap:12px;align-items:center;padding:12px 14px;cursor:pointer}.tray summary::-webkit-details-marker{display:none}.tray .step{width:42px;height:42px;border-radius:14px;display:grid;place-items:center;color:var(--gold);font-weight:700;background:rgba(240,207,146,.08);border:1px solid rgba(240,207,146,.16)}.tray summary strong{display:block}.tray summary small{color:var(--muted);text-transform:uppercase;letter-spacing:.12em}.tray-body{padding:0 14px 14px 68px;color:#d7dfef;line-height:1.6}
111
+ .cards-panel{padding:16px}.candidate-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:14px}.candidate-card{perspective:1200px;min-height:250px}.candidate-card-inner{position:relative;min-height:250px;height:100%;transform-style:preserve-3d;transition:transform .8s cubic-bezier(.2,.7,.1,1)}.candidate-card:hover .candidate-card-inner,.candidate-card:focus .candidate-card-inner{transform:rotateY(180deg)}.candidate-face{position:absolute;inset:0;padding:18px;border-radius:22px;border:1px solid var(--line);backface-visibility:hidden;display:flex;flex-direction:column;gap:12px;box-shadow:var(--shadow), inset 0 1px 0 rgba(255,255,255,.04);background:linear-gradient(180deg,rgba(18,22,31,.98),rgba(11,13,18,.96))}.candidate-face.back{transform:rotateY(180deg);background:linear-gradient(180deg,rgba(28,23,16,.98),rgba(12,11,10,.96))}.top,.meta{display:flex;justify-content:space-between;gap:12px}.chip{font-size:.72rem;letter-spacing:.12em;text-transform:uppercase;color:var(--teal);padding:7px 10px;border-radius:999px;border:1px solid rgba(140,231,220,.18);background:rgba(140,231,220,.08)}.chip.alt{color:var(--gold);border-color:rgba(240,207,146,.18);background:rgba(240,207,146,.08)}.score{font-weight:700;color:var(--gold)}.candidate-face h4{margin:0}.candidate-face p{margin:0;color:#d6deee;line-height:1.6}.meta{margin-top:auto;color:var(--muted)}
112
+ .gr-button-primary{background:linear-gradient(135deg,rgba(240,207,146,.95),rgba(225,178,92,.95))!important;color:#1a1408!important;border:none!important}.gr-button-secondary{background:rgba(255,255,255,.05)!important;color:var(--text)!important;border:1px solid var(--line)!important}
113
+ @media (max-width:1180px){#app-shell .grid{grid-template-columns:1fr}.left{border-right:0;border-bottom:1px solid var(--line)}.model-strip,.candidate-grid{grid-template-columns:1fr}}
114
+ '''
115
+
116
+ HEAD = '''
117
+ <link rel="preconnect" href="https://fonts.googleapis.com">
118
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
119
+ <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">
120
+ <script type="importmap">
121
+ {
122
+ "imports": {
123
+ "three": "https://unpkg.com/three@0.156.0/build/three.module.js",
124
+ "three/addons/": "https://unpkg.com/three@0.156.0/examples/jsm/"
125
+ }
126
+ }
127
+ </script>
128
+ <script type="module">
129
+ import * as THREE from 'three';
130
+ import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
131
+
132
+ function initDVNC(){
133
+ const root = document.getElementById('dvnc-three-root');
134
+ const graph = window.__DVNC_GRAPH__;
135
+ if(!root || !graph || root.dataset.ready === '1') return;
136
+ root.dataset.ready = '1';
137
+ const scene = new THREE.Scene();
138
+ const camera = new THREE.PerspectiveCamera(52, root.clientWidth / root.clientHeight, 0.1, 1000);
139
+ camera.position.set(0, 0, 120);
140
+ const renderer = new THREE.WebGLRenderer({ antialias:true, alpha:true });
141
+ renderer.setSize(root.clientWidth, root.clientHeight);
142
+ renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
143
+ root.innerHTML='';
144
+ root.appendChild(renderer.domElement);
145
+
146
+ const controls = new OrbitControls(camera, renderer.domElement);
147
+ controls.enableDamping = true;
148
+ controls.autoRotate = true;
149
+ controls.autoRotateSpeed = .45;
150
+ controls.enablePan = false;
151
+
152
+ const ambient = new THREE.AmbientLight(0xffffff, .7); scene.add(ambient);
153
+ const key = new THREE.PointLight(0xf6d89b, 2.2, 260); key.position.set(30, 40, 50); scene.add(key);
154
+ const fill = new THREE.PointLight(0x7ee7dd, 1.8, 240); fill.position.set(-40, -20, 40); scene.add(fill);
155
+
156
+ const nodeMeshes = {};
157
+ const active = new Set(graph.active_path || []);
158
+ const palette = {core:0xffffff, domain:0x7ee7dd, bridge:0x91a7ff, mechanism:0xf0cf92, outcome:0xffdbb0, candidate:0xdbb1ff};
159
+ const nodeGeom = new THREE.SphereGeometry(1.8, 22, 22);
160
+ const haloGeom = new THREE.SphereGeometry(3.4, 22, 22);
161
+
162
+ for(const n of graph.nodes || []){
163
+ const mat = new THREE.MeshStandardMaterial({ color: palette[n.group] || 0x9aa8c7, emissive: active.has(n.id) ? 0xf0cf92 : 0x000000, emissiveIntensity: active.has(n.id) ? 1.2 : 0.15, roughness:.3, metalness:.15 });
164
+ const mesh = new THREE.Mesh(nodeGeom, mat);
165
+ mesh.position.set(n.x, n.y, n.z);
166
+ scene.add(mesh);
167
+ nodeMeshes[n.id] = mesh;
168
+ if(active.has(n.id)){
169
+ const halo = new THREE.Mesh(haloGeom, new THREE.MeshBasicMaterial({ color:0xf0cf92, transparent:true, opacity:.08 }));
170
+ halo.position.copy(mesh.position);
171
+ scene.add(halo);
172
+ mesh.userData.halo = halo;
173
+ }
174
+ }
175
+
176
+ function edgeActive(a,b){
177
+ const path = graph.active_path || [];
178
+ const ia = path.indexOf(a), ib = path.indexOf(b);
179
+ return ia >= 0 && ib >= 0 && Math.abs(ia-ib) === 1;
180
+ }
181
+
182
+ for(const e of graph.edges || []){
183
+ const [a,b] = e;
184
+ if(!nodeMeshes[a] || !nodeMeshes[b]) continue;
185
+ const pts = [nodeMeshes[a].position, nodeMeshes[b].position];
186
+ const geo = new THREE.BufferGeometry().setFromPoints(pts);
187
+ const mat = new THREE.LineBasicMaterial({ color: edgeActive(a,b) ? 0xf0cf92 : 0x38465d, transparent:true, opacity: edgeActive(a,b) ? 1 : .45 });
188
+ const line = new THREE.Line(geo, mat);
189
+ line.userData.active = edgeActive(a,b);
190
+ scene.add(line);
191
+ }
192
+
193
+ const stars = new THREE.Points(
194
+ new THREE.BufferGeometry().setAttribute('position', new THREE.Float32BufferAttribute(Array.from({length:1200},()=> (Math.random()-.5)*220), 3)),
195
+ new THREE.PointsMaterial({ color:0x8da6d8, size:.35, transparent:true, opacity:.6 })
196
+ );
197
+ scene.add(stars);
198
+
199
+ const clock = new THREE.Clock();
200
+ function animate(){
201
+ requestAnimationFrame(animate);
202
+ const t = clock.getElapsedTime();
203
+ Object.values(nodeMeshes).forEach((m,i)=>{
204
+ m.scale.setScalar(1 + Math.sin(t*1.6 + i)*0.03);
205
+ if(m.userData.halo){
206
+ const s = 1 + (Math.sin(t*2.2 + i)+1)*0.08;
207
+ m.userData.halo.scale.setScalar(s);
208
+ }
209
+ });
210
+ controls.update();
211
+ renderer.render(scene,camera);
212
+ }
213
+ animate();
214
+
215
+ const resize = ()=>{
216
+ if(!root.clientWidth || !root.clientHeight) return;
217
+ camera.aspect = root.clientWidth / root.clientHeight;
218
+ camera.updateProjectionMatrix();
219
+ renderer.setSize(root.clientWidth, root.clientHeight);
220
+ };
221
+ window.addEventListener('resize', resize, { passive:true });
222
+ }
223
+
224
+ new MutationObserver(()=>initDVNC()).observe(document.documentElement,{childList:true,subtree:true});
225
+ window.addEventListener('load', initDVNC);
226
+ setInterval(initDVNC, 1200);
227
+ </script>
228
+ '''
229
+
230
+ with gr.Blocks(css=CSS, head=HEAD, theme=gr.themes.Base(), fill_height=True) as demo:
231
+ gr.HTML('''
232
+ <div id="app-shell"><div class="grid"><section class="left">
233
+ <div class="hero">
234
+ <div class="brand">
235
+ <div class="logo"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7"><path d="M5 17L12 4l7 13"/><path d="M8.5 12.5h7"/><circle cx="12" cy="12" r="1.8" fill="currentColor" stroke="none"/></svg></div>
236
+ <div><h1>DVNC.AI</h1><p>Connectome-native reasoning · premium scientific discovery interface</p></div>
237
+ </div>
238
+ <div class="live"><i></i><span>Claude-linked runtime</span></div>
239
+ </div>
240
+ ''')
241
+ model_view = gr.HTML(build_models_html("DVNC Sovereign"))
242
+ model = gr.Dropdown(choices=MODELS, value="DVNC Sovereign", label="Model")
243
+ query = gr.Textbox(label="Discovery query", lines=4, elem_classes=["querybox"], placeholder="Ask a scientific question, anomaly, mechanism, or hypothesis target…")
244
+ with gr.Row():
245
+ run_btn = gr.Button("Run discovery", variant="primary")
246
+ example_btn = gr.Button("Load example", variant="secondary")
247
+ chat = gr.HTML('<div class="chat-panel panel"><div class="bubble ai"><span class="role">DVNC</span><p>Enter a discovery prompt to trigger Claude-backed orchestration or demo mode if no API key is set.</p></div></div>')
248
+ gr.HTML('</section><section class="right">')
249
+ connectome = gr.HTML(CONNECTOME_SNIPPET)
250
+ trays = gr.HTML('<div class="panel tray-panel"></div>')
251
+ cards = gr.HTML('<div class="panel cards-panel"></div>')
252
+ output = gr.Markdown('# Discovery Output\n\nAwaiting query.')
253
+ gr.HTML('</section></div></div>')
254
+
255
+ example_btn.click(lambda: "How could a self-assembling conductive biomaterial improve cardiac repair by converting mechanical strain into regenerative signalling?", outputs=query)
256
+ run_btn.click(run, inputs=[query, model], outputs=[model_view, chat, connectome, trays, cards, output])
257
+
258
+ if __name__ == '__main__':
259
+ demo.launch()
dvnc_ai_v2_hf/core/dvnc_engine.py ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import json
3
+ from anthropic import Anthropic
4
+
5
+ DEFAULT_MODEL = "claude-opus-4-7"
6
+ MODEL_MAP = {
7
+ "DVNC Sovereign": "claude-opus-4-7",
8
+ "DVNC Atlas": "claude-sonnet-4-5",
9
+ "DVNC Curie": "claude-sonnet-4-5",
10
+ }
11
+
12
+ SYSTEM_PROMPT = """
13
+ You are DVNC.AI, a connectome-native scientific discovery engine.
14
+ Think in seven explicit phases:
15
+ 1. interpret the question
16
+ 2. locate anomalous tension
17
+ 3. surface distant graph bridges
18
+ 4. produce evidence-aware analogies
19
+ 5. compose a primary hypothesis and alternatives
20
+ 6. critique assumptions adversarially
21
+ 7. output an experiment programme
22
+ Respond in strict JSON.
23
+ """.strip()
24
+
25
+ DEMO_GRAPH = {
26
+ "nodes": [
27
+ {"id": "seed", "label": "Seed Query", "group": "core", "x": 0, "y": 0, "z": 0},
28
+ {"id": "bio", "label": "Biomaterials", "group": "domain", "x": 14, "y": 10, "z": -6},
29
+ {"id": "nano", "label": "Nanostructure", "group": "bridge", "x": 14, "y": -14, "z": 11},
30
+ {"id": "selfasm", "label": "Self-Assembly", "group": "bridge", "x": 30, "y": -8, "z": -10},
31
+ {"id": "electro", "label": "Electro-signalling", "group": "mechanism", "x": 45, "y": 8, "z": -10},
32
+ {"id": "immune", "label": "Immune Modulation", "group": "mechanism", "x": 46, "y": -9, "z": 8},
33
+ {"id": "trial", "label": "Validation", "group": "outcome", "x": 62, "y": 0, "z": 0},
34
+ {"id": "alt1", "label": "Piezoelectric Scaffold", "group": "candidate", "x": 38, "y": 24, "z": 10},
35
+ {"id": "alt2", "label": "Peptide Mesh", "group": "candidate", "x": 35, "y": -24, "z": -10}
36
+ ],
37
+ "edges": [
38
+ ["seed","bio"],["seed","nano"],["bio","immune"],["nano","selfasm"],["selfasm","electro"],["electro","trial"],["immune","trial"],["electro","alt1"],["selfasm","alt2"],["alt1","trial"],["alt2","trial"]
39
+ ],
40
+ "active_path": ["seed","nano","selfasm","electro","trial"]
41
+ }
42
+
43
+ DEMO_REASONING = [
44
+ {"step":1,"agent":"Query Interpreter","tag":"input","summary":"Normalises the seed query and extracts the anomaly that makes discovery worthwhile."},
45
+ {"step":2,"agent":"Graph Divergence Mapper","tag":"graph","summary":"Moves away from nearest-neighbour concepts and surfaces distant but mechanistically relevant bridges."},
46
+ {"step":3,"agent":"Evidence Harvester","tag":"evidence","summary":"Collects evidence packets, counter-signals, and high-uncertainty zones."},
47
+ {"step":4,"agent":"Analogy Engine","tag":"analogy","summary":"Builds mechanism-level analogies instead of stylistic or keyword analogies."},
48
+ {"step":5,"agent":"Hypothesis Composer","tag":"compose","summary":"Creates a lead hypothesis plus alternative discovery cards that can be swapped into the route."},
49
+ {"step":6,"agent":"Adversarial Critic","tag":"critique","summary":"Attacks assumptions, feasibility, safety, and hidden confounders."},
50
+ {"step":7,"agent":"Experimental Program Designer","tag":"experiment","summary":"Produces a staged validation programme with falsification criteria."}
51
+ ]
52
+
53
+ DEMO_CARDS = [
54
+ {
55
+ "title": "Piezoelectric Scaffold Cascade",
56
+ "front": "Convert cardiac motion into local repair signalling through a piezoelectric scaffold.",
57
+ "back": "Alternative route: anomaly -> mechanoelectric transfer -> ion-channel entrainment -> repair response.",
58
+ "score": 92,
59
+ "novelty": "High",
60
+ "agent": "Hypothesis Composer"
61
+ },
62
+ {
63
+ "title": "Peptide Self-Assembly Mesh",
64
+ "front": "Create a peptide mesh that self-assembles at the injury interface and choreographs local repair.",
65
+ "back": "Alternative route: self-assembly -> immune choreography -> regenerative substrate formation.",
66
+ "score": 88,
67
+ "novelty": "High",
68
+ "agent": "Analogy Engine"
69
+ },
70
+ {
71
+ "title": "Immune-Tuned Conductive Hydrogel",
72
+ "front": "Balance conductivity and macrophage-state modulation to reduce scarring while restoring conduction.",
73
+ "back": "Alternative route: inflammation mismatch -> conductive medium -> synchronized healing.",
74
+ "score": 85,
75
+ "novelty": "Medium-High",
76
+ "agent": "Adversarial Critic"
77
+ }
78
+ ]
79
+
80
+
81
+ def _demo_response(query, model_name):
82
+ return {
83
+ "summary": "DVNC.AI selected a deeper discovery route through the graph and preserved alternative branches as swap-ready candidate cards.",
84
+ "primary_hypothesis": "Use a self-assembling conductive scaffold that transforms mechanical strain into regenerative signalling.",
85
+ "graph": DEMO_GRAPH,
86
+ "reasoning": DEMO_REASONING,
87
+ "cards": DEMO_CARDS,
88
+ "metrics": {
89
+ "Novelty": 93,
90
+ "Mechanistic clarity": 89,
91
+ "Experimental tractability": 82,
92
+ "Cross-domain distance": 91
93
+ },
94
+ "model_used": MODEL_MAP.get(model_name, DEFAULT_MODEL),
95
+ "query": query,
96
+ }
97
+
98
+
99
+ def _extract_text(resp):
100
+ parts = []
101
+ for item in resp.content:
102
+ if getattr(item, "type", None) == "text":
103
+ parts.append(item.text)
104
+ return "\n".join(parts).strip()
105
+
106
+
107
+ def _call_claude(query, model_name):
108
+ api_key = os.environ.get("ANTHROPIC_API_KEY")
109
+ if not api_key:
110
+ return _demo_response(query, model_name)
111
+ client = Anthropic(api_key=api_key)
112
+ schema_hint = {
113
+ "summary": "string",
114
+ "primary_hypothesis": "string",
115
+ "graph": {"nodes": [{"id":"string","label":"string","group":"string","x":0,"y":0,"z":0}], "edges": [["a","b"]], "active_path": ["id"]},
116
+ "reasoning": [{"step":1,"agent":"string","tag":"string","summary":"string"}],
117
+ "cards": [{"title":"string","front":"string","back":"string","score":0,"novelty":"string","agent":"string"}],
118
+ "metrics": {"Novelty":0,"Mechanistic clarity":0,"Experimental tractability":0,"Cross-domain distance":0}
119
+ }
120
+ prompt = f"User query: {query}\n\nReturn valid JSON matching this schema exactly: {json.dumps(schema_hint)}"
121
+ response = client.messages.create(
122
+ model=MODEL_MAP.get(model_name, DEFAULT_MODEL),
123
+ max_tokens=1800,
124
+ system=SYSTEM_PROMPT,
125
+ messages=[{"role": "user", "content": prompt}],
126
+ )
127
+ text = _extract_text(response)
128
+ try:
129
+ data = json.loads(text)
130
+ except Exception:
131
+ data = _demo_response(query, model_name)
132
+ data["summary"] = text[:600] if text else data["summary"]
133
+ data["model_used"] = MODEL_MAP.get(model_name, DEFAULT_MODEL)
134
+ data["query"] = query
135
+ return data
136
+
137
+
138
+ def run_discovery(query, model_name):
139
+ return _call_claude(query, model_name)
dvnc_ai_v2_hf/requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio>=5.29.0
2
+ anthropic>=0.51.0
3
+ python-dotenv>=1.0.1
dvnc_ai_v2_hf/ui/connectome.html ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="brain-shell">
2
+ <div class="brain-head">
3
+ <div>
4
+ <p class="eyebrow">Connectome</p>
5
+ <h3>3D Concept Brain</h3>
6
+ </div>
7
+ <div class="brain-help">Active route pulses in gold · orbit to inspect</div>
8
+ </div>
9
+ <div id="dvnc-three-root"></div>
10
+ </div>