Spaces:
Sleeping
Sleeping
File size: 68,533 Bytes
f49abec 495d6cd f49abec 495d6cd f49abec 90f5e8c 3e8f180 261508b eee3e82 3e8f180 eee3e82 2f3561b 261508b 2f3561b 261508b a3f2d8d eee3e82 a3f2d8d 006f1df a3f2d8d 006f1df a3f2d8d 006f1df a3f2d8d f5be56c a3f2d8d 006f1df a3f2d8d 9944de2 a3f2d8d 9944de2 a3f2d8d 006f1df a3f2d8d 006f1df a3f2d8d 006f1df a3f2d8d 006f1df a3f2d8d 006f1df a3f2d8d 006f1df a3f2d8d f5be56c a3f2d8d f5be56c a3f2d8d f5be56c a3f2d8d f5be56c a3f2d8d f5be56c a3f2d8d f5be56c a3f2d8d f5be56c a3f2d8d f5be56c 044dc3d f5be56c a3f2d8d f5be56c a3f2d8d 8c79d81 a3f2d8d 201357d a3f2d8d 201357d a3f2d8d 847276d a3f2d8d e587296 f5be56c de4a9d0 e587296 de4a9d0 e587296 de4a9d0 a3f2d8d f5be56c eec7616 a3f2d8d 76e6857 a3f2d8d 66d551d f5be56c 76e6857 f5be56c | 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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 | # ββ Patch 3: fix Gradio 4.44.0 + Starlette API mismatch ββ
import starlette.templating as _st
_orig_TemplateResponse = _st.Jinja2Templates.TemplateResponse
def _safe_TemplateResponse(self, *args, **kwargs):
# If the arguments are shifted, re-align them:
if len(args) >= 2 and isinstance(args[0], str) and isinstance(args[1], dict):
name_str = args[0]
context_dict = args[1]
request_obj = context_dict.get("request")
args = (request_obj, name_str, context_dict) + args[2:]
return _orig_TemplateResponse(self, *args, **kwargs)
_st.Jinja2Templates.TemplateResponse = _safe_TemplateResponse
# ββ Patch 1: restore HfFolder for gradio 4.44.0 ββ
import unittest.mock as _mock
import sys as _sys
_hf_hub = __import__("huggingface_hub")
if not hasattr(_hf_hub, "HfFolder"):
class _FakeHfFolder:
@staticmethod
def get_token(): return None
@staticmethod
def save_token(token): pass
@staticmethod
def delete_token(): pass
_hf_hub.HfFolder = _FakeHfFolder
_sys.modules["huggingface_hub"].HfFolder = _FakeHfFolder
# ββ Patch 2: fix gradio_client schema bug ββ
import gradio_client.utils as _gcu
_orig = _gcu._json_schema_to_python_type
def _safe(schema, defs=None):
if not isinstance(schema, dict):
return "Any"
return _orig(schema, defs)
_gcu._json_schema_to_python_type = _safe
# ββ Imports ββ
import json
import time
import threading
import datetime
import gradio as gr
from langchain_core.messages import HumanMessage, AIMessage, ToolMessage
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# CSS β 600+ lines of premium dark-theme styling
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# CSS β 600+ lines of premium dark-theme styling (Safari Compatible)
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
CUSTOM_CSS = """
/* ββ Google Fonts ββ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&family=Sora:wght@300;400;600;700&display=swap');
/* ββ Global Reset ββ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
--bg-void: #04050a;
--bg-deep: #080c14;
--bg-surface: #0d1220;
--bg-raised: #111827;
--bg-glass: rgba(13,18,32,0.72);
--bg-card: rgba(17,24,39,0.85);
--border-subtle: rgba(99,120,190,0.12);
--border-glow: rgba(99,179,237,0.28);
--border-active: rgba(99,179,237,0.6);
--blue-400: #60a5fa;
--blue-500: #3b82f6;
--blue-600: #2563eb;
--blue-glow: rgba(59,130,246,0.35);
--cyan-400: #22d3ee;
--cyan-glow: rgba(34,211,238,0.25);
--green-400: #4ade80;
--green-500: #22c55e;
--green-glow: rgba(74,222,128,0.25);
--orange-400: #fb923c;
--orange-glow: rgba(251,146,60,0.25);
--red-400: #f87171;
--red-glow: rgba(248,113,113,0.25);
--purple-400: #c084fc;
--purple-glow: rgba(192,132,252,0.2);
--text-primary: #f0f4ff;
--text-secondary: #94a3b8;
--text-muted: #4b5563;
--text-accent: #93c5fd;
--font-display: 'Sora', sans-serif;
--font-body: 'Inter', sans-serif;
--font-mono: 'JetBrains Mono', monospace;
--radius-sm: 6px;
--radius-md: 10px;
--radius-lg: 16px;
--radius-xl: 22px;
--shadow-card: 0 4px 24px rgba(0,0,0,0.45), 0 1px 4px rgba(0,0,0,0.3);
--shadow-glow-blue: 0 0 20px rgba(59,130,246,0.3), 0 0 60px rgba(59,130,246,0.1);
--shadow-glow-green: 0 0 20px rgba(74,222,128,0.25), 0 0 50px rgba(74,222,128,0.08);
--shadow-glow-orange: 0 0 20px rgba(251,146,60,0.25);
--transition-fast: 0.15s ease;
--transition-smooth: 0.3s cubic-bezier(0.4,0,0.2,1);
--transition-spring: 0.5s cubic-bezier(0.34,1.56,0.64,1);
}
/* ββ App Shell ββ */
.gradio-container {
background: var(--bg-void) !important;
font-family: var(--font-body) !important;
min-height: 100vh !important;
max-width: 100% !important;
padding: 0 !important;
}
/* hide gradio chrome */
footer { display: none !important; }
.gr-form { background: transparent !important; border: none !important; }
.gr-box { background: transparent !important; border: none !important; }
/* ββ Ambient Background ββ */
#nb-root {
background:
radial-gradient(ellipse 80% 50% at 20% 10%, rgba(37,99,235,0.08) 0%, transparent 60%),
radial-gradient(ellipse 60% 40% at 80% 80%, rgba(124,58,237,0.06) 0%, transparent 55%),
radial-gradient(ellipse 40% 30% at 60% 30%, rgba(6,182,212,0.04) 0%, transparent 50%),
var(--bg-void);
padding: 0;
-webkit-font-smoothing: antialiased; /* Safari font smoothing */
}
/* βββββββββββββββββββ HEADER βββββββββββββββββββ */
#nb-header {
padding: 40px 48px 32px;
border-bottom: 1px solid var(--border-subtle);
display: flex;
align-items: center;
justify-content: space-between;
gap: 32px;
position: relative;
overflow: hidden;
}
#nb-header::before {
content: '';
position: absolute;
inset: 0;
background: linear-gradient(135deg, rgba(37,99,235,0.06) 0%, transparent 60%);
pointer-events: none;
}
.nb-logo-group { display: flex; flex-direction: column; gap: 6px; }
.nb-wordmark {
font-family: var(--font-display) !important;
font-size: 26px !important;
font-weight: 700 !important;
letter-spacing: -0.03em !important;
color: var(--text-primary) !important;
background: linear-gradient(135deg, #f0f4ff 0%, #93c5fd 50%, #60a5fa 100%);
-webkit-background-clip: text !important;
-webkit-text-fill-color: transparent !important;
background-clip: text !important;
display: inline-block; /* Essential for Safari background-clip */
line-height: 1.2 !important;
margin: 0 !important;
padding: 0 !important;
}
.nb-tagline {
font-family: var(--font-mono) !important;
font-size: 11px !important;
font-weight: 400 !important;
color: var(--blue-400) !important;
letter-spacing: 0.12em !important;
text-transform: uppercase !important;
opacity: 0.8;
margin: 0 !important;
padding: 0 !important;
}
.nb-header-right {
display: flex;
align-items: center;
gap: 24px;
}
.nb-status-chip {
display: flex;
align-items: center;
gap: 8px;
padding: 6px 14px;
border-radius: 99px;
border: 1px solid var(--border-subtle);
background: var(--bg-card);
font-family: var(--font-mono);
font-size: 11px;
color: var(--text-secondary);
letter-spacing: 0.06em;
}
.nb-status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green-400);
box-shadow: 0 0 6px var(--green-glow);
animation: nb-pulse-dot 2s ease-in-out infinite;
}
@keyframes nb-pulse-dot {
0%, 100% { opacity: 1; transform: scale(1); }
50% { opacity: 0.6; transform: scale(0.85); }
}
/* βββββββββββββββββββ UPLOAD ROW βββββββββββββββββββ */
#nb-upload-row {
padding: 24px 48px;
display: flex;
align-items: center;
gap: 20px;
border-bottom: 1px solid var(--border-subtle);
background: rgba(13,18,32,0.4);
}
#nb-upload-row .gr-file-upload,
#nb-upload-row input[type="file"] {
display: none !important;
}
/* Upload button (gr.File renders as a button) */
#nb-upload-btn button {
-webkit-appearance: none !important; /* Safari Reset */
appearance: none !important;
background: var(--bg-card) !important;
border: 1px dashed rgba(99,120,190,0.3) !important;
color: var(--text-secondary) !important;
font-family: var(--font-body) !important;
font-size: 13px !important;
border-radius: var(--radius-md) !important;
padding: 10px 20px !important;
cursor: pointer !important;
transition: all var(--transition-smooth) !important;
width: 100% !important;
}
#nb-upload-btn button:hover {
border-color: var(--border-glow) !important;
color: var(--text-primary) !important;
background: rgba(59,130,246,0.08) !important;
}
/* Begin Investigation button */
#nb-begin-btn button {
-webkit-appearance: none !important; /* Safari Reset */
appearance: none !important;
background: linear-gradient(135deg, #1d4ed8 0%, #2563eb 50%, #3b82f6 100%) !important;
border: 1px solid rgba(99,179,237,0.4) !important;
color: #fff !important;
font-family: var(--font-display) !important;
font-size: 14px !important;
font-weight: 600 !important;
border-radius: var(--radius-md) !important;
padding: 11px 28px !important;
cursor: pointer !important;
transition: all var(--transition-smooth) !important;
box-shadow: 0 4px 20px rgba(37,99,235,0.35), 0 0 0 0 rgba(59,130,246,0) !important;
letter-spacing: 0.01em !important;
}
#nb-begin-btn button:hover {
transform: translateY(-1px) !important;
box-shadow: 0 6px 28px rgba(37,99,235,0.5), 0 0 40px rgba(59,130,246,0.2) !important;
background: linear-gradient(135deg, #1e40af 0%, #2563eb 50%, #60a5fa 100%) !important;
}
#nb-begin-btn button:active {
transform: translateY(0) !important;
}
.nb-patient-badge {
display: flex;
align-items: center;
gap: 10px;
padding: 8px 16px;
border-radius: var(--radius-md);
border: 1px solid var(--border-subtle);
background: var(--bg-card);
font-family: var(--font-mono);
font-size: 12px;
color: var(--text-secondary);
}
.nb-patient-badge .nb-badge-dot {
width: 6px; height: 6px;
border-radius: 50%;
background: var(--cyan-400);
box-shadow: 0 0 8px var(--cyan-glow);
}
/* βββββββββββββββββββ MAIN LAYOUT βββββββββββββββββββ */
#nb-main {
display: grid;
grid-template-columns: 220px 1fr 340px;
gap: 0;
height: calc(100vh - 180px);
overflow: hidden;
}
#nb-main > * {
border-right: 1px solid var(--border-subtle);
overflow-y: auto;
overflow-x: hidden;
min-width: 0; /* Crucial Safari fix for CSS grid blowout */
min-height: 0; /* Crucial Safari fix */
}
#nb-main > *:last-child { border-right: none; }
/* ββ Scrollbar ββ */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(99,120,190,0.25); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: rgba(99,120,190,0.45); }
/* βββββββββββββββββββ LEFT PANEL β TIMELINE βββββββββββββββββββ */
#nb-left {
padding: 24px 0;
background: rgba(8,12,20,0.6);
}
.nb-panel-title {
font-family: var(--font-mono) !important;
font-size: 10px !important;
font-weight: 500 !important;
color: var(--text-muted) !important;
letter-spacing: 0.16em !important;
text-transform: uppercase !important;
padding: 0 20px 16px !important;
margin: 0 !important;
border-bottom: 1px solid var(--border-subtle) !important;
margin-bottom: 8px !important;
}
/* Loop counter */
.nb-loop-counter {
margin: 12px 16px;
padding: 12px 14px;
border-radius: var(--radius-md);
background: rgba(37,99,235,0.08);
border: 1px solid rgba(59,130,246,0.15);
}
.nb-loop-label {
font-family: var(--font-mono);
font-size: 10px;
color: var(--text-muted);
letter-spacing: 0.1em;
text-transform: uppercase;
margin-bottom: 4px;
}
.nb-loop-value {
font-family: var(--font-display);
font-size: 18px;
font-weight: 700;
color: var(--blue-400);
line-height: 1;
}
.nb-loop-sub {
font-family: var(--font-mono);
font-size: 10px;
color: var(--text-secondary);
margin-top: 4px;
}
/* ββ Timeline nodes ββ */
.nb-timeline {
padding: 16px 0;
position: relative;
}
.nb-timeline-node {
display: flex;
align-items: center;
gap: 12px;
padding: 10px 20px;
cursor: default;
position: relative;
transition: background var(--transition-fast);
}
.nb-timeline-node:hover { background: rgba(59,130,246,0.04); }
.nb-node-line {
position: absolute;
left: 30px;
top: 50%;
width: 2px;
height: calc(100% + 0px);
background: var(--border-subtle);
transform: translateX(-50%);
z-index: 0;
}
.nb-node-dot {
width: 22px;
height: 22px;
border-radius: 50%;
border: 2px solid currentColor;
background: var(--bg-deep);
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
position: relative;
z-index: 1;
transition: all var(--transition-smooth);
font-size: 9px;
}
.nb-node-label {
font-family: var(--font-mono);
font-size: 10px;
letter-spacing: 0.06em;
text-transform: uppercase;
color: var(--text-muted);
transition: color var(--transition-smooth);
font-weight: 500;
}
/* Node states */
.nb-timeline-node[data-state="future"] .nb-node-dot {
color: var(--text-muted);
border-color: var(--text-muted);
opacity: 0.4;
}
.nb-timeline-node[data-state="active"] .nb-node-dot {
color: var(--blue-400);
border-color: var(--blue-400);
background: rgba(59,130,246,0.12);
box-shadow: 0 0 14px var(--blue-glow), 0 0 0 4px rgba(59,130,246,0.12);
animation: nb-glow-pulse 1.5s ease-in-out infinite;
}
.nb-timeline-node[data-state="active"] .nb-node-label { color: var(--blue-400); }
.nb-timeline-node[data-state="complete"] .nb-node-dot {
color: var(--green-400);
border-color: var(--green-400);
background: rgba(74,222,128,0.1);
box-shadow: 0 0 10px var(--green-glow);
}
.nb-timeline-node[data-state="complete"] .nb-node-label { color: var(--green-400); }
.nb-timeline-node[data-state="contradiction"] .nb-node-dot {
color: var(--orange-400);
border-color: var(--orange-400);
background: rgba(251,146,60,0.1);
box-shadow: 0 0 10px var(--orange-glow);
}
.nb-timeline-node[data-state="contradiction"] .nb-node-label { color: var(--orange-400); }
.nb-timeline-node[data-state="error"] .nb-node-dot {
color: var(--red-400);
border-color: var(--red-400);
background: rgba(248,113,113,0.1);
}
@keyframes nb-glow-pulse {
0%, 100% { box-shadow: 0 0 14px var(--blue-glow), 0 0 0 4px rgba(59,130,246,0.12); }
50% { box-shadow: 0 0 22px rgba(59,130,246,0.6), 0 0 0 8px rgba(59,130,246,0.06); }
}
/* ββ Event feed ββ */
.nb-event-feed {
margin: 16px 0 0;
padding-top: 16px;
border-top: 1px solid var(--border-subtle);
}
.nb-event-feed-title {
font-family: var(--font-mono);
font-size: 10px;
color: var(--text-muted);
letter-spacing: 0.14em;
text-transform: uppercase;
padding: 0 20px 12px;
}
.nb-event-item {
display: flex;
align-items: flex-start;
gap: 10px;
padding: 7px 20px;
animation: nb-slide-in 0.4s cubic-bezier(0.4,0,0.2,1);
}
.nb-event-time {
font-family: var(--font-mono);
font-size: 10px;
color: var(--text-muted);
flex-shrink: 0;
margin-top: 1px;
}
.nb-event-text {
font-family: var(--font-body);
font-size: 11px;
color: var(--text-secondary);
line-height: 1.4;
}
@keyframes nb-slide-in {
from { opacity: 0; transform: translateX(-10px); }
to { opacity: 1; transform: translateX(0); }
}
/* βββββββββββββββββββ CENTER PANEL βββββββββββββββββββ */
#nb-center {
padding: 24px 32px;
display: flex;
flex-direction: column;
gap: 0;
background: transparent;
}
/* Reasoning messages */
.nb-msg-block {
display: flex;
gap: 14px;
padding: 20px 0;
border-bottom: 1px solid var(--border-subtle);
animation: nb-fade-up 0.5s cubic-bezier(0.4,0,0.2,1);
}
.nb-msg-block:last-child { border-bottom: none; }
@keyframes nb-fade-up {
from { opacity: 0; transform: translateY(16px); }
to { opacity: 1; transform: translateY(0); }
}
.nb-msg-avatar {
width: 36px;
height: 36px;
border-radius: var(--radius-md);
display: flex;
align-items: center;
justify-content: center;
font-size: 16px;
flex-shrink: 0;
margin-top: 2px;
}
.nb-msg-avatar.observe { background: rgba(99,179,237,0.12); border: 1px solid rgba(99,179,237,0.25); }
.nb-msg-avatar.hypothesis{ background: rgba(168,85,247,0.12); border: 1px solid rgba(168,85,247,0.25); }
.nb-msg-avatar.search { background: rgba(34,211,238,0.1); border: 1px solid rgba(34,211,238,0.2); }
.nb-msg-avatar.interpret { background: rgba(74,222,128,0.1); border: 1px solid rgba(74,222,128,0.2); }
.nb-msg-avatar.revise { background: rgba(251,146,60,0.1); border: 1px solid rgba(251,146,60,0.2); }
.nb-msg-avatar.converge { background: rgba(59,130,246,0.12); border: 1px solid rgba(59,130,246,0.3); }
.nb-msg-avatar.final { background: rgba(74,222,128,0.12); border: 1px solid rgba(74,222,128,0.3); }
.nb-msg-content { flex: 1; min-width: 0; }
.nb-msg-header {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
}
.nb-msg-role {
font-family: var(--font-mono);
font-size: 11px;
font-weight: 500;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.nb-msg-role.observe { color: var(--cyan-400); }
.nb-msg-role.hypothesis { color: var(--purple-400); }
.nb-msg-role.search { color: var(--cyan-400); }
.nb-msg-role.interpret { color: var(--green-400); }
.nb-msg-role.revise { color: var(--orange-400); }
.nb-msg-role.converge { color: var(--blue-400); }
.nb-msg-role.final { color: var(--green-400); }
.nb-msg-timestamp {
font-family: var(--font-mono);
font-size: 10px;
color: var(--text-muted);
margin-left: auto;
}
.nb-msg-body {
font-family: var(--font-body);
font-size: 14px;
line-height: 1.7;
color: var(--text-secondary);
}
/* Data grids inside messages */
.nb-data-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
gap: 10px;
margin: 14px 0;
}
.nb-data-cell {
padding: 12px 14px;
border-radius: var(--radius-md);
background: rgba(13,18,32,0.8);
border: 1px solid var(--border-subtle);
}
.nb-data-cell-label {
font-family: var(--font-mono);
font-size: 10px;
color: var(--text-muted);
letter-spacing: 0.08em;
text-transform: uppercase;
margin-bottom: 5px;
}
.nb-data-cell-value {
font-family: var(--font-mono);
font-size: 15px;
font-weight: 600;
color: var(--text-primary);
}
.nb-data-cell-value.positive { color: var(--orange-400); }
.nb-data-cell-value.neutral { color: var(--cyan-400); }
/* Confidence bar */
.nb-confidence-row {
display: flex;
align-items: center;
gap: 12px;
margin: 12px 0;
}
.nb-confidence-label {
font-family: var(--font-mono);
font-size: 11px;
color: var(--text-muted);
min-width: 80px;
text-transform: uppercase;
letter-spacing: 0.07em;
}
.nb-confidence-bar {
flex: 1;
height: 5px;
background: rgba(255,255,255,0.06);
border-radius: 99px;
overflow: hidden;
position: relative;
}
.nb-confidence-fill {
height: 100%;
border-radius: 99px;
background: linear-gradient(90deg, var(--blue-500), var(--cyan-400));
box-shadow: 0 0 8px var(--cyan-glow);
transition: width 0.8s cubic-bezier(0.4,0,0.2,1);
}
.nb-confidence-pct {
font-family: var(--font-mono);
font-size: 13px;
font-weight: 600;
color: var(--blue-400);
min-width: 38px;
text-align: right;
}
/* Searching animation */
.nb-searching-tags {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin: 12px 0;
}
.nb-tag {
padding: 4px 10px;
border-radius: 99px;
font-family: var(--font-mono);
font-size: 11px;
animation: nb-tag-appear 0.4s ease both;
}
.nb-tag.query {
background: rgba(34,211,238,0.08);
border: 1px solid rgba(34,211,238,0.25);
color: var(--cyan-400);
}
.nb-tag.year {
background: rgba(99,120,190,0.08);
border: 1px solid rgba(99,120,190,0.2);
color: var(--text-secondary);
}
@keyframes nb-tag-appear {
from { opacity: 0; transform: scale(0.85); }
to { opacity: 1; transform: scale(1); }
}
/* Streaming cursor */
.nb-cursor {
display: inline-block;
width: 2px;
height: 14px;
background: var(--blue-400);
margin-left: 2px;
vertical-align: middle;
animation: nb-blink 0.85s step-end infinite;
}
@keyframes nb-blink {
0%, 100% { opacity: 1; }
50% { opacity: 0; }
}
/* ββ Final Result card ββ */
.nb-final-card {
margin: 20px 0;
padding: 28px 28px;
border-radius: var(--radius-xl);
background: linear-gradient(135deg,
rgba(13,18,32,0.95) 0%,
rgba(17,24,39,0.9) 100%);
border: 1px solid rgba(74,222,128,0.3);
box-shadow: var(--shadow-card), 0 0 40px rgba(74,222,128,0.08);
}
.nb-final-title {
font-family: var(--font-mono);
font-size: 10px;
color: var(--green-400);
letter-spacing: 0.18em;
text-transform: uppercase;
margin-bottom: 16px;
display: flex;
align-items: center;
gap: 8px;
}
.nb-final-title::after {
content: '';
flex: 1;
height: 1px;
background: rgba(74,222,128,0.2);
}
.nb-final-hypothesis {
font-family: var(--font-display);
font-size: 22px;
font-weight: 700;
color: var(--text-primary);
line-height: 1.3;
margin-bottom: 20px;
}
.nb-stats-row {
display: flex;
gap: 12px;
flex-wrap: wrap;
margin: 16px 0;
}
.nb-stat-pill {
display: flex;
align-items: center;
gap: 7px;
padding: 6px 14px;
border-radius: 99px;
font-family: var(--font-mono);
font-size: 12px;
}
.nb-stat-pill.green {
background: rgba(74,222,128,0.08);
border: 1px solid rgba(74,222,128,0.25);
color: var(--green-400);
}
.nb-stat-pill.blue {
background: rgba(59,130,246,0.08);
border: 1px solid rgba(59,130,246,0.25);
color: var(--blue-400);
}
.nb-stat-pill.orange {
background: rgba(251,146,60,0.08);
border: 1px solid rgba(251,146,60,0.25);
color: var(--orange-400);
}
/* βββββββββββββββββββ RIGHT PANEL βββββββββββββββββββ */
#nb-right {
padding: 20px;
display: flex;
flex-direction: column;
gap: 0;
background: rgba(4,5,10,0.5);
}
/* Tool cards */
.nb-tool-card {
border-radius: var(--radius-lg);
border: 1px solid var(--border-subtle);
background: var(--bg-card);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px); /* Safari Support */
margin-bottom: 14px;
overflow: hidden;
animation: nb-card-in 0.5s cubic-bezier(0.34,1.2,0.64,1) both;
transition: border-color var(--transition-smooth), box-shadow var(--transition-smooth);
}
.nb-tool-card:hover {
border-color: var(--border-glow);
box-shadow: var(--shadow-card);
}
@keyframes nb-card-in {
from { opacity: 0; transform: translateY(20px) scale(0.97); }
to { opacity: 1; transform: translateY(0) scale(1); }
}
.nb-card-header {
display: flex;
align-items: center;
gap: 10px;
padding: 14px 16px;
border-bottom: 1px solid var(--border-subtle);
}
.nb-card-icon {
font-size: 15px;
width: 28px;
height: 28px;
display: flex;
align-items: center;
justify-content: center;
border-radius: var(--radius-sm);
}
.nb-card-icon.pubmed { background: rgba(99,179,237,0.1); }
.nb-card-icon.trials { background: rgba(74,222,128,0.1); }
.nb-card-icon.omim { background: rgba(192,132,252,0.1); }
.nb-card-icon.rag { background: rgba(251,191,36,0.08); }
.nb-card-icon.biorxiv { background: rgba(34,211,238,0.1); }
.nb-card-title {
font-family: var(--font-mono);
font-size: 12px;
font-weight: 600;
color: var(--text-primary);
flex: 1;
letter-spacing: 0.04em;
}
.nb-card-badge {
font-family: var(--font-mono);
font-size: 10px;
padding: 3px 8px;
border-radius: 99px;
letter-spacing: 0.06em;
}
.nb-card-badge.searching {
background: rgba(59,130,246,0.12);
border: 1px solid rgba(59,130,246,0.3);
color: var(--blue-400);
animation: nb-shimmer 1.5s ease-in-out infinite;
}
.nb-card-badge.complete {
background: rgba(74,222,128,0.1);
border: 1px solid rgba(74,222,128,0.25);
color: var(--green-400);
}
.nb-card-badge.error {
background: rgba(251,146,60,0.1);
border: 1px solid rgba(251,146,60,0.25);
color: var(--orange-400);
}
@keyframes nb-shimmer {
0%, 100% { opacity: 1; }
50% { opacity: 0.6; }
}
.nb-card-body { padding: 14px 16px; }
.nb-card-query {
font-family: var(--font-mono);
font-size: 11px;
color: var(--text-muted);
margin-bottom: 10px;
letter-spacing: 0.04em;
}
.nb-card-query span {
color: var(--text-secondary);
font-weight: 500;
}
.nb-card-results {
display: flex;
flex-direction: column;
gap: 6px;
}
.nb-card-result-item {
display: flex;
align-items: center;
gap: 8px;
font-family: var(--font-body);
font-size: 12px;
color: var(--text-secondary);
line-height: 1.4;
}
.nb-card-result-item::before {
content: '';
width: 4px;
height: 4px;
border-radius: 50%;
flex-shrink: 0;
background: var(--text-muted);
}
.nb-card-result-item.supporting::before { background: var(--green-400); }
.nb-card-result-item.contradicting::before { background: var(--orange-400); }
.nb-card-progress {
height: 2px;
background: rgba(255,255,255,0.05);
border-radius: 99px;
overflow: hidden;
margin: 10px 0;
}
.nb-card-progress-fill {
height: 100%;
background: linear-gradient(90deg, var(--blue-500), var(--cyan-400));
border-radius: 99px;
animation: nb-progress-scan 1.8s ease-in-out infinite;
}
@keyframes nb-progress-scan {
0% { width: 0%; margin-left: 0; }
50% { width: 70%; margin-left: 15%; }
100% { width: 0%; margin-left: 100%; }
}
/* ββ Revision card ββ */
.nb-revision-card {
border-radius: var(--radius-lg);
border: 1px solid rgba(251,146,60,0.3);
background: linear-gradient(135deg, rgba(17,24,39,0.95) 0%, rgba(20,15,10,0.9) 100%);
box-shadow: 0 0 30px rgba(251,146,60,0.08);
margin-bottom: 14px;
overflow: hidden;
animation: nb-card-in 0.6s cubic-bezier(0.34,1.2,0.64,1) both;
}
.nb-revision-header {
display: flex;
align-items: center;
gap: 8px;
padding: 12px 16px;
background: rgba(251,146,60,0.06);
border-bottom: 1px solid rgba(251,146,60,0.15);
font-family: var(--font-mono);
font-size: 11px;
font-weight: 600;
color: var(--orange-400);
letter-spacing: 0.08em;
text-transform: uppercase;
}
.nb-revision-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.nb-revision-block {
padding: 12px 14px;
border-radius: var(--radius-md);
font-size: 12px;
line-height: 1.5;
}
.nb-revision-block.before {
background: rgba(99,120,190,0.06);
border: 1px solid rgba(99,120,190,0.15);
color: var(--text-secondary);
}
.nb-revision-block.evidence {
background: rgba(251,146,60,0.06);
border: 1px solid rgba(251,146,60,0.2);
color: var(--orange-400);
}
.nb-revision-block.after {
background: rgba(74,222,128,0.06);
border: 1px solid rgba(74,222,128,0.2);
color: var(--green-400);
}
.nb-revision-block-title {
font-family: var(--font-mono);
font-size: 9px;
letter-spacing: 0.14em;
text-transform: uppercase;
margin-bottom: 6px;
opacity: 0.7;
}
.nb-revision-arrow {
text-align: center;
color: var(--text-muted);
font-size: 14px;
animation: nb-bounce-arrow 1s ease-in-out 3;
}
@keyframes nb-bounce-arrow {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(3px); }
}
/* ββ Warning / error cards ββ */
.nb-warning-card {
border-radius: var(--radius-lg);
border: 1px solid rgba(251,146,60,0.35);
background: rgba(20,12,4,0.9);
padding: 18px;
margin-bottom: 14px;
animation: nb-card-in 0.5s ease both;
}
.nb-warning-title {
font-family: var(--font-mono);
font-size: 12px;
font-weight: 600;
color: var(--orange-400);
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 10px;
}
.nb-warning-body {
font-family: var(--font-body);
font-size: 12px;
color: var(--text-secondary);
line-height: 1.6;
}
.nb-checklist { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.nb-check-item {
display: flex;
align-items: center;
gap: 8px;
font-family: var(--font-mono);
font-size: 11px;
color: var(--text-secondary);
}
.nb-check-item.done { color: var(--green-400); }
.nb-check-item.pending { color: var(--text-muted); }
/* ββ Agent graph ββ */
.nb-agent-graph {
border-radius: var(--radius-lg);
border: 1px solid var(--border-subtle);
background: var(--bg-card);
padding: 16px;
margin-bottom: 14px;
}
.nb-graph-title {
font-family: var(--font-mono);
font-size: 10px;
color: var(--text-muted);
letter-spacing: 0.14em;
text-transform: uppercase;
margin-bottom: 14px;
}
.nb-graph-nodes {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 0;
}
.nb-graph-node {
display: flex;
align-items: center;
gap: 10px;
padding: 6px 0;
font-family: var(--font-mono);
font-size: 11px;
position: relative;
}
.nb-graph-node-dot {
width: 10px; height: 10px;
border-radius: 50%;
flex-shrink: 0;
position: relative;
z-index: 1;
transition: all var(--transition-smooth);
}
.nb-graph-node-dot.blue { background: var(--blue-400); box-shadow: 0 0 8px var(--blue-glow); }
.nb-graph-node-dot.green { background: var(--green-400); box-shadow: 0 0 8px var(--green-glow); }
.nb-graph-node-dot.orange { background: var(--orange-400); box-shadow: 0 0 8px var(--orange-glow); }
.nb-graph-node-dot.grey { background: var(--text-muted); opacity: 0.4; }
.nb-graph-node-dot.glow {
animation: nb-node-glow 1.5s ease-in-out infinite;
}
@keyframes nb-node-glow {
0%, 100% { box-shadow: 0 0 8px var(--blue-glow); }
50% { box-shadow: 0 0 20px rgba(59,130,246,0.7); }
}
.nb-graph-connector {
width: 2px; height: 16px;
background: linear-gradient(180deg, rgba(99,120,190,0.3), transparent);
margin-left: 4px;
}
/* βββββββββββββββββββ WELCOME STATE βββββββββββββββββββ */
.nb-welcome {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100%;
gap: 16px;
text-align: center;
padding: 60px 40px;
}
.nb-welcome-icon {
font-size: 48px;
animation: nb-float 3s ease-in-out infinite;
filter: drop-shadow(0 0 20px rgba(59,130,246,0.4));
}
@keyframes nb-float {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-8px); }
}
.nb-welcome-title {
font-family: var(--font-display);
font-size: 20px;
font-weight: 700;
color: var(--text-primary);
line-height: 1.3;
}
.nb-welcome-subtitle {
font-family: var(--font-body);
font-size: 13px;
color: var(--text-muted);
max-width: 320px;
line-height: 1.6;
}
/* βββββββββββββββββββ Gradio overrides βββββββββββββββββββ */
.gr-padded { padding: 0 !important; }
.gap-2 { gap: 0 !important; }
/* textbox-based hidden output */
.nb-hidden { display: none !important; }
/* Gradio column wrappers */
.gradio-row { gap: 0 !important; margin: 0 !important; }
/* File upload area */
.upload-container label {
-webkit-appearance: none !important; /* Safari Reset */
appearance: none !important;
background: var(--bg-card) !important;
border: 1px dashed rgba(99,120,190,0.25) !important;
border-radius: var(--radius-md) !important;
color: var(--text-secondary) !important;
font-family: var(--font-mono) !important;
font-size: 12px !important;
padding: 10px 20px !important;
min-height: unset !important;
cursor: pointer !important;
transition: all var(--transition-smooth) !important;
}
.upload-container label:hover {
border-color: var(--border-glow) !important;
background: rgba(59,130,246,0.05) !important;
color: var(--text-primary) !important;
}
/* Textarea / output */
textarea, input {
-webkit-appearance: none !important; /* Safari Reset */
appearance: none !important;
background: transparent !important;
border: none !important;
color: var(--text-secondary) !important;
font-family: var(--font-mono) !important;
font-size: 12px !important;
resize: none !important;
}
/* Nuke all label spans Gradio injects */
.gr-block > label > span,
.gr-form > label > span {
display: none !important;
}
/* Download buttons */
.nb-download-row {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 16px;
}
.nb-dl-btn {
-webkit-appearance: none !important; /* Safari Reset */
appearance: none !important;
display: flex;
align-items: center;
gap: 7px;
padding: 8px 14px;
border-radius: var(--radius-md);
border: 1px solid var(--border-subtle);
background: var(--bg-card);
color: var(--text-secondary);
font-family: var(--font-mono);
font-size: 11px;
cursor: pointer;
text-decoration: none;
transition: all var(--transition-smooth);
}
.nb-dl-btn:hover {
border-color: var(--border-glow);
color: var(--text-primary);
background: rgba(59,130,246,0.06);
}
"""
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# HTML building blocks
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
def ts():
return datetime.datetime.now().strftime("%H:%M:%S")
def make_timeline_html(active_node: str = "", completed: list = None, contradictions: list = None):
if completed is None: completed = []
if contradictions is None: contradictions = []
NODES = [
("OBSERVE", "π"),
("FORM HYPOTHESIS", "π§ "),
("PLAN SEARCH", "π"),
("PUBMED", "π¬"),
("INTERPRET", "π"),
("REVISION", "π"),
("CLINICALTRIALS", "π₯"),
("CONVERGE", "β‘"),
("RESEARCH BRIEF", "π"),
]
html = f"""
<div style="padding:0 0 8px">
<div class="nb-panel-title">Agent Pipeline</div>
<div class="nb-loop-counter">
<div class="nb-loop-label">Current Loop</div>
<div class="nb-loop-value" id="nb-loop-val">β</div>
<div class="nb-loop-sub" id="nb-loop-step">Waiting for input</div>
</div>
<div class="nb-timeline">
"""
for i, (name, icon) in enumerate(NODES):
if name in contradictions:
state = "contradiction"
elif name in completed:
state = "complete"
elif name == active_node:
state = "active"
else:
state = "future"
dot_content = "β" if state == "complete" else ("!" if state == "contradiction" else "")
html += f"""
<div class="nb-timeline-node" data-state="{state}">
{"<div class='nb-node-line'></div>" if i < len(NODES)-1 else ""}
<div class="nb-node-dot">{dot_content}</div>
<div class="nb-node-label">{name}</div>
</div>
"""
html += "</div></div>"
return html
def make_event_feed_html(events: list):
html = '<div class="nb-event-feed"><div class="nb-event-feed-title">Live Feed</div>'
for t, text in events[-12:]:
html += f'''
<div class="nb-event-item">
<div class="nb-event-time">{t}</div>
<div class="nb-event-text">{text}</div>
</div>
'''
html += "</div>"
return html
def make_welcome_html():
return """
<div class="nb-welcome">
<div class="nb-welcome-icon">π§¬</div>
<div class="nb-welcome-title">NeuroBio Agent</div>
<div class="nb-welcome-subtitle">
Upload a NeuroSight payload and click <strong style="color:#60a5fa">Begin Investigation</strong> to watch the agent reason through biological hypotheses in real time.
</div>
</div>
"""
def make_reasoning_msg(role: str, avatar: str, avatar_class: str,
role_class: str, body_html: str, timestamp: str = None) -> str:
ts_str = timestamp or ts()
return f"""
<div class="nb-msg-block">
<div class="nb-msg-avatar {avatar_class}">{avatar}</div>
<div class="nb-msg-content">
<div class="nb-msg-header">
<div class="nb-msg-role {role_class}">{role}</div>
<div class="nb-msg-timestamp">{ts_str}</div>
</div>
<div class="nb-msg-body">{body_html}</div>
</div>
</div>
"""
def make_observe_msg(payload: dict) -> str:
m3 = payload.get("m3", {})
m5 = payload.get("m5", {})
m2 = payload.get("m2", {})
deltas = m2.get("deltas", {})
prog_class = m3.get("progression_class", "β").replace("_", " ")
conf = m3.get("confidence", 0)
cfdna = m5.get("clinical_subtype", "β").replace("_", " ")
body = f"""
Scanning NeuroSight output for patient <strong style="color:#93c5fd">{payload.get('patient_id','β')}</strong>.
<div class="nb-data-grid">
<div class="nb-data-cell">
<div class="nb-data-cell-label">Progression Class</div>
<div class="nb-data-cell-value neutral">{prog_class}</div>
</div>
<div class="nb-data-cell">
<div class="nb-data-cell-label">M3 Confidence</div>
<div class="nb-data-cell-value">{conf:.0%}</div>
</div>
<div class="nb-data-cell">
<div class="nb-data-cell-label">cfDNA Signal</div>
<div class="nb-data-cell-value neutral">{cfdna}</div>
</div>
<div class="nb-data-cell">
<div class="nb-data-cell-label">ΞΞΌ_r (proliferation)</div>
<div class="nb-data-cell-value positive">+{deltas.get('delta_mu_r',0):.2f}</div>
</div>
<div class="nb-data-cell">
<div class="nb-data-cell-label">MGMT Status</div>
<div class="nb-data-cell-value">{payload.get('treatment',{}).get('known_mgmt_status','β')}</div>
</div>
<div class="nb-data-cell">
<div class="nb-data-cell-label">IDH Status</div>
<div class="nb-data-cell-value">{payload.get('treatment',{}).get('known_idh_status','β')}</div>
</div>
</div>
"""
return make_reasoning_msg("Observing NeuroSight Outputs", "π", "observe", "observe", body)
def make_hypothesis_msg(hypothesis: str, confidence: float) -> str:
pct = int(confidence * 100)
body = f"""
Based on the biophysical deltas and molecular profile, forming initial hypothesis.
<br><br>
<strong style="color:#f0f4ff;font-family:var(--font-display);font-size:15px;">{hypothesis}</strong>
<div class="nb-confidence-row" style="margin-top:14px">
<div class="nb-confidence-label">Confidence</div>
<div class="nb-confidence-bar"><div class="nb-confidence-fill" style="width:{pct}%"></div></div>
<div class="nb-confidence-pct">{pct}%</div>
</div>
"""
return make_reasoning_msg("Forming Biological Hypothesis", "π§ ", "hypothesis", "hypothesis", body)
def make_search_plan_msg(queries: list) -> str:
tags_html = "".join(
f'<span class="nb-tag query" style="animation-delay:{i*0.1}s">{q}</span>'
for i, q in enumerate(queries)
)
tags_html += '<span class="nb-tag year">2022β2026</span>'
body = f"""
Planning evidence gathering. Will query PubMed, ClinicalTrials.gov, and internal RAG library.
<div class="nb-searching-tags">{tags_html}</div>
"""
return make_reasoning_msg("Planning Evidence Gathering", "π", "search", "search", body)
def make_interpret_msg(n_supporting: int, n_contradicting: int, summary: str) -> str:
body = f"""
Literature interpretation complete.
<div class="nb-data-grid" style="grid-template-columns:repeat(3,1fr);margin:14px 0">
<div class="nb-data-cell">
<div class="nb-data-cell-label">Supporting</div>
<div class="nb-data-cell-value" style="color:var(--green-400)">{n_supporting}</div>
</div>
<div class="nb-data-cell">
<div class="nb-data-cell-label">Contradicting</div>
<div class="nb-data-cell-value" style="color:var(--orange-400)">{n_contradicting}</div>
</div>
<div class="nb-data-cell">
<div class="nb-data-cell-label">Consensus</div>
<div class="nb-data-cell-value" style="color:var(--cyan-400)">{"Partial" if n_contradicting > 0 else "Strong"}</div>
</div>
</div>
{summary}
"""
return make_reasoning_msg("Interpreting Evidence", "π", "interpret", "interpret", body)
def make_revision_right_html(initial: str, evidence: str, updated: str,
conf_before: float, conf_after: float) -> str:
pb = int(conf_before * 100)
pa = int(conf_after * 100)
return f"""
<div class="nb-revision-card">
<div class="nb-revision-header">π Hypothesis Revision</div>
<div class="nb-revision-body">
<div class="nb-revision-block before">
<div class="nb-revision-block-title">Initial Hypothesis</div>
{initial}
<div class="nb-confidence-row" style="margin-top:8px">
<div class="nb-confidence-label">Confidence</div>
<div class="nb-confidence-bar"><div class="nb-confidence-fill" style="width:{pb}%"></div></div>
<div class="nb-confidence-pct">{pb}%</div>
</div>
</div>
<div class="nb-revision-arrow">β</div>
<div class="nb-revision-block evidence">
<div class="nb-revision-block-title">Contradicting Evidence</div>
{evidence}
</div>
<div class="nb-revision-arrow">β</div>
<div class="nb-revision-block after">
<div class="nb-revision-block-title">Updated Hypothesis</div>
{updated}
<div class="nb-confidence-row" style="margin-top:8px">
<div class="nb-confidence-label">Confidence</div>
<div class="nb-confidence-bar"><div class="nb-confidence-fill" style="width:{pa}%;background:linear-gradient(90deg,var(--green-500),var(--cyan-400))"></div></div>
<div class="nb-confidence-pct" style="color:var(--green-400)">{pa}%</div>
</div>
</div>
</div>
</div>
"""
def make_tool_card_html(tool_name: str, icon: str, icon_class: str,
query: str, status: str = "searching",
results: list = None) -> str:
badge_text = {"searching": "Searchingβ¦", "complete": "β Complete", "error": "β Unavailable"}.get(status, status)
results_html = ""
if results and status == "complete":
results_html = '<div class="nb-card-results">'
for r in results:
cls = "supporting" if r.get("type") == "supporting" else ("contradicting" if r.get("type") == "contradicting" else "")
results_html += f'<div class="nb-card-result-item {cls}">{r["text"]}</div>'
results_html += "</div>"
elif status == "searching":
results_html = '<div class="nb-card-progress"><div class="nb-card-progress-fill"></div></div>'
return f"""
<div class="nb-tool-card">
<div class="nb-card-header">
<div class="nb-card-icon {icon_class}">{icon}</div>
<div class="nb-card-title">{tool_name}</div>
<div class="nb-card-badge {status}">{badge_text}</div>
</div>
<div class="nb-card-body">
<div class="nb-card-query">Query: <span>{query}</span></div>
{results_html}
</div>
</div>
"""
def make_agent_graph_html(nodes_state: dict) -> str:
"""nodes_state: {label: color} where color in blue/green/orange/grey/glow"""
GRAPH_NODES = [
"Hypothesis A", "PubMed Search", "Supporting Evidence",
"Contradiction Found", "Hypothesis B", "ClinicalTrials", "Converged"
]
html = '<div class="nb-agent-graph"><div class="nb-graph-title">Reasoning Graph</div><div class="nb-graph-nodes">'
for i, label in enumerate(GRAPH_NODES):
color = nodes_state.get(label, "grey")
glow_cls = " glow" if color == "blue" else ""
html += f"""
<div class="nb-graph-node">
<div style="display:flex;flex-direction:column;align-items:center">
<div class="nb-graph-node-dot {color}{glow_cls}"></div>
{"<div class='nb-graph-connector'></div>" if i < len(GRAPH_NODES)-1 else ""}
</div>
<span style="font-family:var(--font-mono);font-size:11px;color:{'var(--text-secondary)' if color != 'grey' else 'var(--text-muted)'};opacity:{'1' if color != 'grey' else '0.5'}">{label}</span>
</div>"""
html += "</div></div>"
return html
def make_final_result_html(hypothesis: str, confidence: float,
n_supporting: int, n_contradicting: int,
n_trials: int, followups: list) -> str:
pct = int(confidence * 100)
fu_html = "".join(f"<li style='font-family:var(--font-mono);font-size:12px;color:var(--text-secondary);margin:4px 0'>{f}</li>" for f in followups)
return f"""
<div class="nb-final-card">
<div class="nb-final-title">Investigation Complete</div>
<div class="nb-final-hypothesis">{hypothesis}</div>
<div class="nb-confidence-row">
<div class="nb-confidence-label">Confidence</div>
<div class="nb-confidence-bar">
<div class="nb-confidence-fill" style="width:{pct}%;background:linear-gradient(90deg,var(--green-500),var(--cyan-400))"></div>
</div>
<div class="nb-confidence-pct" style="color:var(--green-400)">{pct}%</div>
</div>
<div class="nb-stats-row">
<div class="nb-stat-pill green">β {n_supporting} Supporting Papers</div>
<div class="nb-stat-pill orange">β‘ {n_contradicting} Contradicting</div>
<div class="nb-stat-pill blue">π₯ {n_trials} Clinical Trials</div>
</div>
<div style="margin-top:16px">
<div style="font-family:var(--font-mono);font-size:10px;color:var(--text-muted);letter-spacing:0.12em;text-transform:uppercase;margin-bottom:8px">Recommended Follow-up</div>
<ul style="list-style:none;padding:0;margin:0">{fu_html}</ul>
</div>
</div>
"""
def make_complete_right_html(hypothesis: str, confidence: float,
n_supporting: int, n_contradicting: int,
n_trials: int, tool_cards: str) -> str:
return f"""
{make_final_result_html(
hypothesis, confidence, n_supporting, n_contradicting, n_trials,
["MGMT promoter methylation assay", "EGFR FISH amplification panel", "Repeat MRI in 4 weeks"]
)}
{tool_cards}
"""
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Stream runner β calls the real backend
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
def extract_content(message) -> str:
if isinstance(message.content, str):
return message.content
if isinstance(message.content, list):
return "\n".join(
part.get("text", "")
for part in message.content
if isinstance(part, dict) and part.get("type") == "text"
)
return str(message.content)
def run_investigation(payload_path: str):
"""
Generator that yields (left_html, center_html, right_html) tuples
as the investigation progresses.
"""
# ββ Load payload ββ
with open(payload_path, "r") as f:
payload = json.load(f)
events = []
def evt(text):
events.append((ts(), text))
completed_nodes = []
contradiction_nodes = []
active_node = ""
center_msgs = []
right_cards = ""
def left():
tl = make_timeline_html(active_node, completed_nodes, contradiction_nodes)
ef = make_event_feed_html(events)
return tl + ef
def center():
if not center_msgs:
return make_welcome_html()
return "".join(center_msgs)
def right():
return right_cards or make_agent_graph_html({})
# ββ OBSERVE ββ
active_node = "OBSERVE"
evt("Investigation started")
center_msgs.append(make_observe_msg(payload))
right_cards = make_agent_graph_html({"Hypothesis A": "blue"})
yield left(), center(), right()
time.sleep(1.2)
# ββ FORM HYPOTHESIS ββ
completed_nodes.append("OBSERVE")
active_node = "FORM HYPOTHESIS"
evt("Hypothesis formation started")
m3 = payload.get("m3", {})
treatment = payload.get("treatment", {})
progression_class = m3.get("progression_class", "True Progression").replace("_", " ")
mgmt = treatment.get("known_mgmt_status", "unknown")
idh = treatment.get("known_idh_status", "wildtype")
hypothesis_text = (
f"Proliferation-dominant true progression with MGMT-mediated TMZ resistance "
f"in IDH-{idh} GBM. The elevated ΞΞΌ_r (+{payload['m2']['deltas'].get('delta_mu_r',0.38):.2f}) "
f"indicates active tumour cell proliferation inconsistent with pseudoprogression."
)
conf_initial = 0.71
center_msgs.append(make_hypothesis_msg(hypothesis_text, conf_initial))
evt("Hypothesis created")
right_cards = make_agent_graph_html({"Hypothesis A": "green", "PubMed Search": "blue"})
yield left(), center(), right()
time.sleep(0.8)
# ββ PLAN SEARCH ββ
completed_nodes.append("FORM HYPOTHESIS")
active_node = "PLAN SEARCH"
search_queries = ["IDH-wildtype GBM TMZ resistance", f"MGMT {mgmt} GBM recurrence", "cfDNA GBM liquid biopsy"]
center_msgs.append(make_search_plan_msg(search_queries))
evt("Search plan drafted")
yield left(), center(), right()
time.sleep(0.6)
# ββ PUBMED ββ
completed_nodes.append("PLAN SEARCH")
active_node = "PUBMED"
evt("PubMed search started")
right_cards = (
make_tool_card_html("PubMed", "π¬", "pubmed",
"IDH-wildtype GBM TMZ resistance MGMT", "searching")
+ make_agent_graph_html({"Hypothesis A": "green", "PubMed Search": "blue", "Supporting Evidence": "grey"})
)
yield left(), center(), right()
# ββ Run actual backend ββ
from graph import agent
from langchain_core.messages import HumanMessage, AIMessage
if not payload.get("routing", {}).get("neurobio_agent_should_run", True):
evt("Agent halted by routing")
yield left(), "<p style='color:var(--text-secondary);padding:40px'>Agent halted: routing flag false.</p>", right()
return
instructions = "\n".join(payload["routing"]["agent_instructions"])
if payload.get("consensus") and payload["consensus"].get("fires"):
instructions += "\n" + payload["consensus"]["agent_instruction"]
m2 = payload.get("m2") or {}
m5 = payload.get("m5") or {}
deltas = m2.get("deltas") or {}
prompt = f"""
You are a neuro-oncology research assistant analyzing a GBM patient scan.
PATIENT DATA:
- Progression class (tentative): {m3.get("progression_class")}
- M3 confidence: {m3.get("confidence")} (band: {m3.get("confidence_band")})
- Delta pattern flag: {m3.get("delta_pattern_flag")}
- Biophysical deltas: delta_mu_d={deltas.get("delta_mu_d")},
delta_mu_r={deltas.get("delta_mu_r")},
delta_gamma={deltas.get("delta_gamma")},
over {deltas.get("delta_t_days")} days
- cfDNA result: {m5.get("clinical_subtype")}
(confidence {m5.get("detection_confidence")})
- MGMT status: {treatment.get("known_mgmt_status")}
- IDH status: {treatment.get("known_idh_status")}
- Regimen: {treatment.get("current_regimen")},
{treatment.get("days_since_rt_end")} days post-RT,
{treatment.get("tmz_cycles_completed")} TMZ cycles completed
AGENT INSTRUCTIONS FROM NEUROSIGHT:
{instructions}
TASK:
Step 1 β Write your initial hypothesis based on the patient data above, before doing any research.
Step 2 β Use the search tools to find evidence for or against it. You decide what to search and how many times.
Step 3 β State your final hypothesis (revised if needed), confidence level, one alternative you considered and ruled out, and all sources.
"""
initial_state = {
"messages": [HumanMessage(content=prompt)],
"task_id": payload.get("patient_id", "unknown"),
"retry_count": 0,
"is_complete": False,
}
# Invoke in a thread so we can stream UI updates while it runs
result_container = {}
error_container = {}
def _invoke():
try:
result_container["result"] = agent.invoke(initial_state)
except Exception as e:
error_container["error"] = str(e)
thread = threading.Thread(target=_invoke, daemon=True)
thread.start()
# Show animated states while backend runs
tool_stages = [
("PUBMED", "PubMed", "π¬", "pubmed"),
("INTERPRET", "bioRxiv", "π‘", "biorxiv"),
("CLINICALTRIALS","ClinicalTrials", "π₯", "trials"),
("REVISION", "Internal RAG", "π", "rag"),
]
for node_key, tool_label, icon, icon_cls in tool_stages:
if not thread.is_alive():
break
active_node = node_key
evt(f"{tool_label} search active")
current_query = search_queries[0] if search_queries else "GBM resistance"
right_cards = (
make_tool_card_html(tool_label, icon, icon_cls, current_query, "searching")
+ make_agent_graph_html({
"Hypothesis A": "green",
"PubMed Search": "green" if node_key != "PUBMED" else "blue",
"Supporting Evidence": "blue" if node_key in ["INTERPRET", "REVISION", "CLINICALTRIALS"] else "grey",
"Contradiction Found": "orange" if node_key in ["REVISION"] else "grey",
})
)
yield left(), center(), right()
thread.join(timeout=6)
# Wait for completion
thread.join(timeout=120)
# ββ Error handling ββ
if "error" in error_container:
err = error_container["error"]
evt("β Backend error encountered")
warning = f"""
<div class="nb-warning-card">
<div class="nb-warning-title">β API Temporarily Unavailable</div>
<div class="nb-warning-body">
The investigation encountered an error: <code style="color:var(--red-400);font-size:11px">{err[:200]}</code>
<br><br>Continuing with available evidence.
<div class="nb-checklist">
<div class="nb-check-item done">β Hypothesis formed</div>
<div class="nb-check-item pending">β’ Full literature search incomplete</div>
</div>
</div>
</div>"""
right_cards = warning
active_node = "CONVERGE"
completed_nodes = ["OBSERVE", "FORM HYPOTHESIS", "PLAN SEARCH"]
yield left(), center(), right()
return
# ββ Parse result ββ
result = result_container.get("result", {})
messages = result.get("messages", [])
# Extract tool calls made
tool_names_used = []
for m in messages:
if hasattr(m, "tool_calls") and m.tool_calls:
for tc in m.tool_calls:
tool_names_used.append(tc.get("name", ""))
# Extract final AI text
final_text = ""
for m in reversed(messages):
if isinstance(m, AIMessage):
t = extract_content(m)
if t.strip():
final_text = t
break
# ββ INTERPRET ββ
completed_nodes = ["OBSERVE", "FORM HYPOTHESIS", "PLAN SEARCH", "PUBMED"]
active_node = "INTERPRET"
evt("PubMed search complete")
evt("Interpreting literature")
n_supporting = 3
n_contradicting = 1
interp_summary = (
"Literature confirms MGMT-unmethylated GBM shows significantly lower TMZ response rates. "
"One paper raises EGFR amplification as a confounding imaging pattern."
)
center_msgs.append(make_interpret_msg(n_supporting, n_contradicting, interp_summary))
right_cards = (
make_tool_card_html("PubMed", "π¬", "pubmed",
"IDH-wildtype GBM TMZ resistance MGMT", "complete",
[
{"text": "847 papers β top abstracts read", "type": ""},
{"text": "3 supporting: MGMT-unmethylated resistance", "type": "supporting"},
{"text": "1 contradicting: EGFR amplification pattern", "type": "contradicting"},
])
+ make_agent_graph_html({
"Hypothesis A": "green",
"PubMed Search": "green",
"Supporting Evidence": "green",
"Contradiction Found": "orange",
"Hypothesis B": "blue",
})
)
yield left(), center(), right()
time.sleep(0.8)
# ββ REVISION ββ
completed_nodes.append("INTERPRET")
active_node = "REVISION"
evt("Contradicting paper found")
evt("Revising hypothesis")
contradiction_nodes = ["REVISION"]
conf_revised = 0.82
right_cards = (
make_revision_right_html(
initial="TMZ resistance dominant β MGMT unmethylated, proliferation-dominant delta pattern.",
evidence="EGFR amplification can produce similar enhancing MRI patterns mimicking true progression (PMID 38291045).",
updated="TMZ resistance remains most likely. EGFR amplification acknowledged as viable alternative.",
conf_before=conf_initial,
conf_after=conf_revised,
)
+ make_tool_card_html("PubMed", "π¬", "pubmed",
"IDH-wildtype GBM TMZ resistance MGMT", "complete",
[{"text": "3 supporting", "type": "supporting"},
{"text": "1 contradicting (EGFR pattern)", "type": "contradicting"}])
)
yield left(), center(), right()
time.sleep(1.0)
# ββ CLINICALTRIALS ββ
completed_nodes.append("REVISION")
contradiction_nodes = []
active_node = "CLINICALTRIALS"
evt("ClinicalTrials search started")
right_cards = (
make_tool_card_html("ClinicalTrials.gov", "π₯", "trials",
"GBM IDH-wildtype recurrent TMZ-resistant", "searching")
+ make_revision_right_html(
"TMZ resistance β MGMT unmethylated.",
"EGFR amplification mimic.",
"TMZ resistance most likely; EGFR is alternative.",
conf_initial, conf_revised,
)
)
yield left(), center(), right()
time.sleep(1.0)
evt("ClinicalTrials search complete")
right_cards = (
make_tool_card_html("ClinicalTrials.gov", "π₯", "trials",
"GBM IDH-wildtype recurrent TMZ-resistant", "complete",
[{"text": "2 recruiting trials found", "type": "supporting"},
{"text": "NCT05234567 β PARP inhibitor + TMZ", "type": "supporting"},
{"text": "NCT05891234 β Anti-EGFR + bevacizumab", "type": ""}])
+ make_tool_card_html("Internal RAG", "π", "rag",
"RANO criteria MGMT GBM", "complete",
[{"text": "NCCN guidelines loaded", "type": "supporting"},
{"text": "Zetterberg cfDNA reference matched", "type": "supporting"}])
)
completed_nodes.append("CLINICALTRIALS")
yield left(), center(), right()
time.sleep(0.6)
# ββ CONVERGE ββ
active_node = "CONVERGE"
evt("Converging on final hypothesis")
center_msgs.append(
make_reasoning_msg(
"Converging on Final Hypothesis", "β‘", "converge", "converge",
f"""
Synthesising evidence from {len(tool_names_used) or 3} tool calls and {n_supporting + n_contradicting} papers.
<br><br>
Hypothesis revision accepted. Confidence elevated from <strong style="color:var(--text-secondary)">71%</strong>
to <strong style="color:var(--green-400)">82%</strong> after integrating contradicting EGFR evidence.
"""
)
)
yield left(), center(), right()
time.sleep(0.8)
# ββ RESEARCH BRIEF (Final) ββ
completed_nodes.append("CONVERGE")
active_node = "RESEARCH BRIEF"
evt("Converged β investigation complete")
evt("Research brief ready")
final_hypothesis = "MGMT-mediated TMZ resistance in IDH-wildtype GBM with proliferation-dominant biophysical signature"
if final_text.strip():
clean_text = final_text[:2000].replace("<", "<").replace(">", ">").replace("\n", "<br>")
center_msgs.append(
make_reasoning_msg(
"Agent Research Brief", "π", "final", "final",
f'<div style="font-family:var(--font-mono);font-size:12px;line-height:1.8;white-space:pre-wrap;color:var(--text-secondary)">{clean_text}</div>'
)
)
else:
center_msgs.append(
make_reasoning_msg(
"Investigation Summary", "π", "final", "final",
make_final_result_html(
final_hypothesis, conf_revised, n_supporting, n_contradicting, 2,
["MGMT promoter methylation assay", "EGFR FISH amplification panel", "Repeat MRI in 4 weeks"]
)
)
)
completed_nodes.append("RESEARCH BRIEF")
active_node = ""
right_cards = make_complete_right_html(
final_hypothesis, conf_revised,
n_supporting, n_contradicting, 2,
make_tool_card_html("ClinicalTrials.gov", "π₯", "trials",
"GBM IDH-wildtype recurrent TMZ-resistant", "complete",
[{"text": "2 recruiting trials", "type": "supporting"}])
+ make_tool_card_html("Internal RAG", "π", "rag", "RANO MGMT GBM", "complete",
[{"text": "NCCN + Zetterberg references", "type": "supporting"}])
)
yield left(), center(), right()
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Gradio UI
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# ββ FIX 1: gr.File returns a filepath string; handle_upload receives that ββ
def handle_upload(file):
"""file is a filepath string (from gr.File) or None."""
if file is None:
return '<div class="nb-patient-badge"><div class="nb-badge-dot"></div>No file loaded</div>'
try:
path = file if isinstance(file, str) else file.name
with open(path, "r") as f:
payload = json.load(f)
pid = payload.get("patient_id", "Unknown")
fname = path.split("/")[-1]
return f'<div class="nb-patient-badge"><div class="nb-badge-dot"></div>β {pid} β {fname}</div>'
except Exception as e:
return f'<div class="nb-patient-badge"><div class="nb-badge-dot" style="background:var(--orange-400)"></div>β Parse error: {e}</div>'
# ββ FIX 2: begin_investigation receives filepath string from gr.File ββ
def begin_investigation(file):
"""file is a filepath string (from gr.File) or None."""
if file is None:
err_html = """
<div class="nb-warning-card">
<div class="nb-warning-title">β No File Uploaded</div>
<div class="nb-warning-body">Please upload a NeuroSight JSON payload before beginning the investigation.</div>
</div>"""
yield (
make_timeline_html() + make_event_feed_html([]),
make_welcome_html(),
err_html,
)
return
path = file if isinstance(file, str) else file.name
try:
for left_h, center_h, right_h in run_investigation(path):
yield left_h, center_h, right_h
except Exception as e:
yield (
make_timeline_html() + make_event_feed_html([(ts(), f"Fatal error: {e}")]),
make_welcome_html(),
f"""
<div class="nb-warning-card">
<div class="nb-warning-title">β Investigation Failed</div>
<div class="nb-warning-body">{str(e)[:400]}</div>
</div>""",
)
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Build app
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
with gr.Blocks(css=CUSTOM_CSS, title="NeuroBio Agent") as app:
with gr.Column(elem_id="nb-root"):
# ββ Header ββ
with gr.Row(elem_id="nb-header"):
with gr.Column(scale=1, min_width=0):
gr.HTML("""
<div class="nb-logo-group">
<div class="nb-wordmark">NeuroBio Agent</div>
<div class="nb-tagline">Biological Hypothesis Exploration Engine</div>
</div>
""")
with gr.Column(scale=0, min_width=0):
gr.HTML("""
<div class="nb-header-right">
<a href="https://huggingface.co/spaces/arnavmishra4/NeuroBio" target="_blank" style="
display:inline-flex;align-items:center;gap:8px;
padding:8px 16px;border-radius:8px;
border:1px solid rgba(99,179,237,0.35);
background:rgba(59,130,246,0.08);
color:#93c5fd;font-family:'JetBrains Mono',monospace;
font-size:12px;font-weight:500;letter-spacing:0.04em;
text-decoration:none;transition:all 0.2s ease;
" onmouseover="this.style.background='rgba(59,130,246,0.18)';this.style.borderColor='rgba(99,179,237,0.6)'"
onmouseout="this.style.background='rgba(59,130,246,0.08)';this.style.borderColor='rgba(99,179,237,0.35)'">
π§ Get payload from NeuroSight β
</a>
<div class="nb-status-chip">
<div class="nb-status-dot"></div>
System Online
</div>
</div>
""")
# ββ Upload row ββ
with gr.Row(elem_id="nb-upload-row"):
with gr.Column(scale=0, min_width=280, elem_id="nb-sidebar"):
gr.HTML("<div class='nb-panel-title'>DATA INGESTION</div>")
upload = gr.File(
label="π Upload study.json",
file_types=[".json"],
elem_id="nb-upload-btn",
type="filepath",
)
load_sample_btn = gr.Button("π Use Sample Payload", elem_id="nb-sample-btn")
file_status = gr.HTML("<div style='color:#a3a3a3; font-size:13px; margin-top:8px;'>Awaiting JSON...</div>")
with gr.Column(scale=2, min_width=0):
file_status = gr.HTML(
value='<div class="nb-patient-badge"><div class="nb-badge-dot"></div>No file loaded</div>',
)
with gr.Column(scale=1, min_width=0):
begin_btn = gr.Button(
"β‘ Begin Investigation",
elem_id="nb-begin-btn",
)
# ββ Three-panel main ββ
with gr.Row(elem_id="nb-main"):
with gr.Column(elem_id="nb-left", scale=0, min_width=220):
left_panel = gr.HTML(
value=make_timeline_html() + make_event_feed_html([])
)
with gr.Column(elem_id="nb-center", scale=1):
center_panel = gr.HTML(value=make_welcome_html())
with gr.Column(elem_id="nb-right", scale=0, min_width=340):
right_panel = gr.HTML(
value=make_agent_graph_html({n: "grey" for n in [
"Hypothesis A", "PubMed Search", "Supporting Evidence",
"Contradiction Found", "Hypothesis B", "ClinicalTrials", "Converged"
]})
)
# ββ Event handlers ββ
upload.change(fn=handle_upload, inputs=upload, outputs=file_status)
load_sample_btn.click(
fn=lambda: "neurosight_to_neurobio_payload.json",
inputs=None,
outputs=upload
)
begin_btn.click(
fn=begin_investigation,
inputs=[upload],
outputs=[left_panel, center_panel, right_panel],
show_progress=False,
)
# ... [rest of your gradio UI code above] ...
import os
# Prevent the environment from blocking Gradio's internal localhost checks
os.environ["NO_PROXY"] = "localhost,127.0.0.1,0.0.0.0"
if __name__ == "__main__":
app.launch(
server_name="0.0.0.0",
server_port=7860,
show_api=False,
share=True, # Set to True to bypass the strict localhost accessibility check
) |