""" DVNC.AI — root app.py Fixed: all internal module imports now use correct underscore names matching the actual function/constant names in dvnc_ai_v2_hf/. """ # ── Standard library ────────────────────────────────────────────────────── import html import random import re import sys from pathlib import Path from typing import Dict, List, Optional # Ensure the repository root is on sys.path so the package is importable ROOT = Path(__file__).resolve().parent if str(ROOT) not in sys.path: sys.path.insert(0, str(ROOT)) # ── Third-party ─────────────────────────────────────────────────────────── import gradio as gr # ── Internal modules ────────────────────────────────────────────────────── from dvnc_ai_v2_hf.agent_route_cards import build_agent_route_cards_html from dvnc_ai_v2_hf.discovery_app_bridge import ( get_default_route_state, get_discovery_css, get_initial_discovery_timeline_html, ) from dvnc_ai_v2_hf.dvnc_ui_layout import get_dvnc_layout_css from dvnc_ai_v2_hf.graph_canvas_patch import render_graph_canvas_html from dvnc_ai_v2_hf.self_learning_graph import ( DEFAULT_SOURCES, SEARCH_MODES, SOURCE_OPTIONS, build_journal_html, ingest_selected_papers, parse_uploaded_pdf, render_parse_result, run_paper_discovery, safe_text, ) # ── Constants ───────────────────────────────────────────────────────────── MODELS = [ { "name": "DVNC Sovereign", "tag": "flagship", "desc": "Maximum depth orchestration for frontier discovery", }, { "name": "DVNC Atlas", "tag": "research", "desc": "Balanced reasoning, graph traversal, and synthesis", }, { "name": "DVNC Curie", "tag": "lab", "desc": "Experimental hypothesis generation for anomalous signals", }, ] AGENTS = [ "Query Interpreter", "Graph Divergence Mapper", "Evidence Harvester", "Analogy Engine", "Hypothesis Composer", "Adversarial Critic", "Experimental Program Designer", ] NODES = [ {"id": "seed", "label": "Seed Query", "group": "core", "x": 10, "y": 0, "z": 0}, {"id": "bio", "label": "Biomaterials", "group": "domain", "x": 24, "y": 12, "z": -8}, {"id": "card", "label": "Cardiac Repair", "group": "domain", "x": 38, "y": 3, "z": 14}, {"id": "nano", "label": "Nanostructure", "group": "bridge", "x": 24, "y": -18, "z": 16}, {"id": "selfasm", "label": "Self-Assembly", "group": "bridge", "x": 40, "y": -16, "z": -16}, {"id": "electro", "label": "Electro-signalling", "group": "mechanism", "x": 58, "y": 10, "z": -10}, {"id": "immune", "label": "Immune Modulation", "group": "mechanism", "x": 64, "y": -8, "z": 10}, {"id": "trial", "label": "Validation Path", "group": "outcome", "x": 80, "y": 0, "z": 0}, {"id": "alt1", "label": "Piezoelectric Scaffold", "group": "candidate", "x": 56, "y": 26, "z": 14}, {"id": "alt2", "label": "Peptide Mesh", "group": "candidate", "x": 54, "y": -27, "z": -14}, ] EDGES = [ ("seed", "bio"), ("seed", "nano"), ("bio", "card"), ("nano", "selfasm"), ("selfasm", "electro"), ("card", "immune"), ("electro", "trial"), ("immune", "trial"), ("card", "alt1"), ("selfasm", "alt2"), ("alt1", "trial"), ("alt2", "trial"), ] DEFAULT_PATH = ["seed", "nano", "selfasm", "electro", "trial"] CANDIDATES = [ { "title": "Piezoelectric Scaffold Cascade", "front": "Use mechano-electric scaffolds to convert cardiac strain into micro-current signalling.", "back": "Discovery path: anomalous healing signal -> piezoelectric analog -> ion-channel entrainment -> tissue regeneration. Risk: power density and fibrosis coupling.", "score": 92, "novelty": "High", "agent": "Hypothesis Composer", }, { "title": "Peptide Self-Assembly Mesh", "front": "Deploy dynamic peptide meshes that self-assemble around damaged myocardium and guide repair.", "back": "Discovery path: self-assembly -> local immune choreography -> regenerative substrate formation. Risk: degradation timing and targeting specificity.", "score": 88, "novelty": "High", "agent": "Analogy Engine", }, { "title": "Immune-Tuned Conductive Hydrogel", "front": "Blend conductivity with macrophage-state modulation to reduce scarring and restore conduction.", "back": "Discovery path: inflammation mismatch -> conductive medium -> macrophage polarization -> synchronized healing. Risk: persistence and biocompatibility.", "score": 85, "novelty": "Medium-High", "agent": "Adversarial Critic", }, ] ACADEMIC_INSIGHTS = [ { "hypothesis": "Implementation of mechano-electric scaffolds to transduce cardiac strain into localized micro-current signalling for myocardial regeneration.", "metrics": { "Novelty": 92, "Mechanistic clarity": 85, "Experimental tractability": 78, "Cross-domain distance": 94, }, "outline": ( "1. Synthesize candidate piezoelectric biomaterial scaffolds with tunable strain-electric coupling.\n" "2. Evaluate in vitro electromechanical transduction and subsequent ion-channel entrainment.\n" "3. Conduct in vivo comparative models to assess regenerative efficacy against gold-standard substrates.\n" "4. Rigorously validate to exclude pathological fibrosis and power-density toxicity." ), "path": ["seed", "bio", "card", "alt1", "trial"], }, { "hypothesis": "Deployment of dynamic peptide networks that self-assemble post-infarction to orchestrate local immunological responses and guide substrate regeneration.", "metrics": { "Novelty": 88, "Mechanistic clarity": 82, "Experimental tractability": 86, "Cross-domain distance": 85, }, "outline": ( "1. Formulate peptide sequences programmed for triggered in situ self-assembly within the myocardial infarct zone.\n" "2. Quantify macrophage polarization and local immune choreography post-deployment.\n" "3. Map the temporospatial degradation profile against de novo tissue formation.\n" "4. Falsify against off-target aggregation and delayed clearance risks." ), "path": ["seed", "nano", "selfasm", "alt2", "trial"], }, { "hypothesis": "Integration of conductive hydrogels with immunomodulatory properties to simultaneously bridge electrical uncoupling and mitigate adverse fibrotic scarring.", "metrics": { "Novelty": 85, "Mechanistic clarity": 90, "Experimental tractability": 88, "Cross-domain distance": 79, }, "outline": ( "1. Fabricate biocompatible hydrogels featuring precisely tuned electrical conductivity and immunomodulatory motifs.\n" "2. Monitor electrophysiological synchronization across the scaffold-tissue interface.\n" "3. Assess macrophage state transitions and suppression of adverse fibrotic remodelling.\n" "4. Validate long-term persistence, hemocompatibility, and mechanical integration." ), "path": ["seed", "bio", "card", "immune", "trial"], }, ] # ── Utility helpers ─────────────────────────────────────────────────────── def norm_text(x: Optional[str]) -> str: return re.sub(r"\s+", " ", (x or "")).strip() def build_learning_graph_html(nodes, edges, title="Self-Learning Knowledge Graph"): return render_graph_canvas_html( { "status": "ok" if (nodes or edges) else "empty", "nodes": nodes or [], "edges": edges or [], }, title=title, height=780, ) # ── HTML builders ───────────────────────────────────────────────────────── def build_connectome_html(path_ids: List[str]) -> str: active = set(path_ids) node_map = {n["id"]: n for n in NODES} path_pairs = { pair for i in range(len(path_ids) - 1) for pair in [(path_ids[i], path_ids[i + 1]), (path_ids[i + 1], path_ids[i])] } baselines, activelines, circles, labels = [], [], [], [] for a, b in EDGES: na, nb = node_map[a], node_map[b] x1, y1 = na["x"] * 8 + 80, na["y"] * 6 + 280 x2, y2 = nb["x"] * 8 + 80, nb["y"] * 6 + 280 baselines.append(f'e class="edge" x1="{x1}" y1="{y1}" x2="{x2}" y2="{y2}"/>') if (a, b) in path_pairs: activelines.append(f'e class="edge active" x1="{x1}" y1="{y1}" x2="{x2}" y2="{y2}"/>') for n in NODES: cx, cy = n["x"] * 8 + 80, n["y"] * 6 + 280 is_active = n["id"] in active state = "chosen" if is_active else "idle" halo_cls = "halo active" if is_active else "halo" lbl_cls = "label active" if is_active else "label" radius = 18 if is_active else 13 halo_r = 30 if is_active else 0 circles.append( f'ircle class="{halo_cls}" cx="{cx}" cy="{cy}" r="{halo_r}"/>' f'ircle class="node {state}" cx="{cx}" cy="{cy}" r="{radius}"/>' f'
Connectome
{safe_text(c["front"])}
{safe_text(c["back"])}
{safe_text(query)}
{safe_text(result["summary"])}
Primary hypothesis: {safe_text(result["primary_hypothesis"])}