Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -1,550 +1,724 @@
|
|
| 1 |
-
from __future__ import annotations
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
import
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
import
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
from datetime import datetime, timedelta
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
"""Sundew Diabetes Commons – holistic, open Streamlit experience."""
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
import json
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
import logging
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
import math
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
import time
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
from dataclasses import dataclass
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
from typing import Any, Dict, List, Optional, Tuple
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
import numpy as np
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
import pandas as pd
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
import streamlit as st
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
from sklearn.linear_model import LogisticRegression
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
from sklearn.pipeline import Pipeline
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
from sklearn.preprocessing import StandardScaler
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
try:
|
| 47 |
+
|
| 48 |
+
from sundew import SundewAlgorithm # type: ignore[attr-defined]
|
| 49 |
+
|
| 50 |
+
from sundew.config import SundewConfig
|
| 51 |
+
|
| 52 |
+
from sundew.config_presets import get_preset
|
| 53 |
+
|
| 54 |
+
_HAS_SUNDEW = True
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
except Exception: # fallback when package is unavailable
|
| 58 |
+
|
| 59 |
+
SundewAlgorithm = None # type: ignore
|
| 60 |
+
|
| 61 |
+
SundewConfig = object # type: ignore
|
| 62 |
+
|
| 63 |
+
def get_preset(_: str) -> Any: # type: ignore
|
| 64 |
+
|
| 65 |
+
return None
|
| 66 |
+
|
| 67 |
+
_HAS_SUNDEW = False
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
LOGGER = logging.getLogger("sundew.diabetes.commons")
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
@dataclass
|
| 74 |
+
class SundewGateConfig:
|
| 75 |
+
|
| 76 |
+
target_activation: float = 0.22
|
| 77 |
+
|
| 78 |
+
temperature: float = 0.08
|
| 79 |
+
|
| 80 |
+
mode: str = "tuned_v2"
|
| 81 |
+
|
| 82 |
+
use_native: bool = True
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def _build_sundew_runtime(config: SundewGateConfig) -> Optional[SundewAlgorithm]:
|
| 86 |
+
|
| 87 |
+
if not (config.use_native and _HAS_SUNDEW and SundewAlgorithm is not None):
|
| 88 |
+
|
| 89 |
+
return None
|
| 90 |
+
|
| 91 |
+
try:
|
| 92 |
+
|
| 93 |
+
preset = get_preset(config.mode)
|
| 94 |
+
|
| 95 |
+
except Exception:
|
| 96 |
+
|
| 97 |
+
preset = SundewConfig() # type: ignore
|
| 98 |
+
|
| 99 |
+
for attr, value in (
|
| 100 |
+
("target_activation_rate", config.target_activation),
|
| 101 |
+
("gate_temperature", config.temperature),
|
| 102 |
+
):
|
| 103 |
+
|
| 104 |
+
try:
|
| 105 |
+
|
| 106 |
+
setattr(preset, attr, value)
|
| 107 |
+
|
| 108 |
+
except Exception:
|
| 109 |
+
|
| 110 |
+
pass
|
| 111 |
+
|
| 112 |
+
for constructor in (
|
| 113 |
+
lambda: SundewAlgorithm(preset), # type: ignore[arg-type]
|
| 114 |
+
lambda: SundewAlgorithm(config=preset), # type: ignore[arg-type]
|
| 115 |
+
lambda: SundewAlgorithm(),
|
| 116 |
+
):
|
| 117 |
+
|
| 118 |
+
try:
|
| 119 |
+
|
| 120 |
+
return constructor()
|
| 121 |
+
|
| 122 |
+
except Exception:
|
| 123 |
+
|
| 124 |
+
continue
|
| 125 |
+
|
| 126 |
+
return None
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
class AdaptiveGate:
|
| 130 |
+
"""Adapter that hides Sundew/Fallback branching."""
|
| 131 |
+
|
| 132 |
+
def __init__(self, config: SundewGateConfig) -> None:
|
| 133 |
+
|
| 134 |
+
self.config = config
|
| 135 |
+
|
| 136 |
+
self._ema = 0.0
|
| 137 |
+
|
| 138 |
+
self._tau = float(np.clip(config.target_activation, 0.05, 0.95))
|
| 139 |
+
|
| 140 |
+
self._alpha = 0.05
|
| 141 |
+
|
| 142 |
+
self.sundew: Optional[SundewAlgorithm] = _build_sundew_runtime(config)
|
| 143 |
+
|
| 144 |
+
def decide(self, score: float) -> bool:
|
| 145 |
+
|
| 146 |
+
if self.sundew is not None:
|
| 147 |
+
|
| 148 |
+
for attr in ("decide", "step", "open"):
|
| 149 |
+
|
| 150 |
+
fn = getattr(self.sundew, attr, None)
|
| 151 |
+
|
| 152 |
+
if callable(fn):
|
| 153 |
+
|
| 154 |
+
try:
|
| 155 |
+
|
| 156 |
+
return bool(fn(score))
|
| 157 |
+
|
| 158 |
+
except Exception:
|
| 159 |
+
|
| 160 |
+
continue
|
| 161 |
+
|
| 162 |
+
normalized = float(np.clip(score / 1.4, 0.0, 1.0))
|
| 163 |
+
|
| 164 |
+
temperature = max(self.config.temperature, 0.02)
|
| 165 |
+
|
| 166 |
+
probability = 1.0 / (1.0 + math.exp(-(normalized - self._tau) / temperature))
|
| 167 |
+
|
| 168 |
+
fired = bool(np.random.rand() < probability)
|
| 169 |
+
|
| 170 |
+
self._ema = (1 - self._alpha) * self._ema + self._alpha * (
|
| 171 |
+
1.0 if fired else 0.0
|
| 172 |
+
)
|
| 173 |
+
|
| 174 |
+
self._tau += 0.05 * (self.config.target_activation - self._ema)
|
| 175 |
+
|
| 176 |
+
self._tau = float(np.clip(self._tau, 0.05, 0.95))
|
| 177 |
+
|
| 178 |
+
return fired
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
def load_example_dataset(n_rows: int = 720) -> pd.DataFrame:
|
| 182 |
+
|
| 183 |
+
rng = np.random.default_rng(17)
|
| 184 |
+
|
| 185 |
+
t0 = pd.Timestamp.utcnow().floor("5min") - pd.Timedelta(minutes=5 * n_rows)
|
| 186 |
+
|
| 187 |
+
timestamps = [t0 + pd.Timedelta(minutes=5 * i) for i in range(n_rows)]
|
| 188 |
+
|
| 189 |
+
base = 118 + 28 * np.sin(np.linspace(0, 7 * math.pi, n_rows))
|
| 190 |
+
|
| 191 |
+
noise = rng.normal(0, 12, n_rows)
|
| 192 |
+
|
| 193 |
+
meals = (rng.random(n_rows) < 0.05).astype(float) * rng.normal(50, 18, n_rows).clip(
|
| 194 |
+
0, 150
|
| 195 |
+
)
|
| 196 |
+
|
| 197 |
+
insulin = (rng.random(n_rows) < 0.03).astype(float) * rng.normal(
|
| 198 |
+
4.2, 1.5, n_rows
|
| 199 |
+
).clip(0, 10)
|
| 200 |
+
|
| 201 |
+
steps = rng.integers(0, 200, size=n_rows)
|
| 202 |
+
|
| 203 |
+
heart_rate = 68 + (steps > 90) * rng.integers(20, 45, size=n_rows)
|
| 204 |
+
|
| 205 |
+
sleep_flag = (rng.random(n_rows) < 0.12).astype(float)
|
| 206 |
+
|
| 207 |
+
stress_index = rng.uniform(0, 1, n_rows)
|
| 208 |
+
|
| 209 |
+
glucose = base + noise
|
| 210 |
+
|
| 211 |
+
for i in range(n_rows):
|
| 212 |
+
|
| 213 |
+
if i >= 6:
|
| 214 |
+
|
| 215 |
+
glucose[i] += 0.4 * meals[i - 6 : i].sum() / 6
|
| 216 |
+
|
| 217 |
+
if i >= 4:
|
| 218 |
+
|
| 219 |
+
glucose[i] -= 1.2 * insulin[i - 4 : i].sum() / 4
|
| 220 |
+
|
| 221 |
+
if steps[i] > 100:
|
| 222 |
+
|
| 223 |
+
glucose[i] -= 15
|
| 224 |
+
|
| 225 |
+
glucose[180:200] = rng.normal(62, 5, 20)
|
| 226 |
+
|
| 227 |
+
glucose[350:365] = rng.normal(210, 10, 15)
|
| 228 |
+
|
| 229 |
+
return pd.DataFrame(
|
| 230 |
+
{
|
| 231 |
+
"timestamp": timestamps,
|
| 232 |
+
"glucose_mgdl": np.round(np.clip(glucose, 40, 350), 1),
|
| 233 |
+
"carbs_g": np.round(meals, 1),
|
| 234 |
+
"insulin_units": np.round(insulin, 1),
|
| 235 |
+
"steps": steps.astype(int),
|
| 236 |
+
"hr": (heart_rate + rng.normal(0, 5, n_rows)).round().astype(int),
|
| 237 |
+
"sleep_flag": sleep_flag,
|
| 238 |
+
"stress_index": stress_index,
|
| 239 |
+
}
|
| 240 |
+
)
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
def compute_features(df: pd.DataFrame) -> pd.DataFrame:
|
| 244 |
+
|
| 245 |
+
df = df.copy().sort_values("timestamp").reset_index(drop=True)
|
| 246 |
+
|
| 247 |
+
df["timestamp"] = pd.to_datetime(df["timestamp"], utc=True)
|
| 248 |
+
|
| 249 |
+
df["glucose_prev"] = df["glucose_mgdl"].shift(1)
|
| 250 |
+
|
| 251 |
+
dt = (
|
| 252 |
+
df["timestamp"].astype("int64") - df["timestamp"].shift(1).astype("int64")
|
| 253 |
+
) / 60e9
|
| 254 |
+
|
| 255 |
+
df["roc_mgdl_min"] = (df["glucose_mgdl"] - df["glucose_prev"]) / dt
|
| 256 |
+
|
| 257 |
+
df["roc_mgdl_min"] = df["roc_mgdl_min"].replace([np.inf, -np.inf], 0.0).fillna(0.0)
|
| 258 |
+
|
| 259 |
+
ema = df["glucose_mgdl"].ewm(span=48, adjust=False).mean()
|
| 260 |
+
|
| 261 |
+
df["deviation"] = (df["glucose_mgdl"] - ema).fillna(0.0)
|
| 262 |
+
|
| 263 |
+
df["iob_proxy"] = df["insulin_units"].rolling(12, min_periods=1).sum() / 12.0
|
| 264 |
+
|
| 265 |
+
df["cob_proxy"] = df["carbs_g"].rolling(12, min_periods=1).sum() / 12.0
|
| 266 |
+
|
| 267 |
+
df["variability"] = df["glucose_mgdl"].rolling(24, min_periods=2).std().fillna(0.0)
|
| 268 |
+
|
| 269 |
+
df["activity_factor"] = (df["steps"] / 200.0 + df["hr"] / 160.0).clip(0, 1)
|
| 270 |
+
|
| 271 |
+
df["sleep_flag"] = df["sleep_flag"].fillna(0.0) if "sleep_flag" in df else 0.0
|
| 272 |
+
|
| 273 |
+
df["stress_index"] = df["stress_index"].fillna(0.5) if "stress_index" in df else 0.5
|
| 274 |
+
|
| 275 |
+
return df[
|
| 276 |
+
[
|
| 277 |
+
"timestamp",
|
| 278 |
+
"glucose_mgdl",
|
| 279 |
+
"roc_mgdl_min",
|
| 280 |
+
"deviation",
|
| 281 |
+
"iob_proxy",
|
| 282 |
+
"cob_proxy",
|
| 283 |
+
"variability",
|
| 284 |
+
"activity_factor",
|
| 285 |
+
"sleep_flag",
|
| 286 |
+
"stress_index",
|
| 287 |
+
]
|
| 288 |
+
].copy()
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
def lightweight_score(row: pd.Series) -> float:
|
| 292 |
+
|
| 293 |
+
glucose = row["glucose_mgdl"]
|
| 294 |
+
|
| 295 |
+
roc = row["roc_mgdl_min"]
|
| 296 |
+
|
| 297 |
+
deviation = row["deviation"]
|
| 298 |
+
|
| 299 |
+
iob = row["iob_proxy"]
|
| 300 |
+
|
| 301 |
+
cob = row["cob_proxy"]
|
| 302 |
+
|
| 303 |
+
stress = row["stress_index"]
|
| 304 |
+
|
| 305 |
+
score = 0.0
|
| 306 |
+
|
| 307 |
+
score += max(0.0, (glucose - 180) / 80)
|
| 308 |
+
|
| 309 |
+
score += max(0.0, (70 - glucose) / 30)
|
| 310 |
+
|
| 311 |
+
score += abs(roc) / 6.0
|
| 312 |
+
|
| 313 |
+
score += abs(deviation) / 100.0
|
| 314 |
+
|
| 315 |
+
score += stress * 0.4
|
| 316 |
+
|
| 317 |
+
score += max(0.0, (cob - iob) * 0.04)
|
| 318 |
+
|
| 319 |
+
return float(np.clip(score, 0.0, 1.4))
|
| 320 |
+
|
| 321 |
+
|
| 322 |
+
def train_simple_model(df: pd.DataFrame):
|
| 323 |
+
|
| 324 |
+
features = df[
|
| 325 |
+
[
|
| 326 |
+
"glucose_mgdl",
|
| 327 |
+
"roc_mgdl_min",
|
| 328 |
+
"iob_proxy",
|
| 329 |
+
"cob_proxy",
|
| 330 |
+
"activity_factor",
|
| 331 |
+
"variability",
|
| 332 |
+
]
|
| 333 |
+
]
|
| 334 |
+
|
| 335 |
+
labels = (df["glucose_mgdl"] > 180).astype(int)
|
| 336 |
+
|
| 337 |
+
model = Pipeline(
|
| 338 |
+
[
|
| 339 |
+
("scaler", StandardScaler()),
|
| 340 |
+
("clf", LogisticRegression(max_iter=400, class_weight="balanced")),
|
| 341 |
+
]
|
| 342 |
+
)
|
| 343 |
+
|
| 344 |
+
try:
|
| 345 |
+
|
| 346 |
+
model.fit(features, labels)
|
| 347 |
+
|
| 348 |
+
return model
|
| 349 |
+
|
| 350 |
+
except Exception:
|
| 351 |
+
|
| 352 |
+
return None
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
def render_overview(
|
| 356 |
+
results: pd.DataFrame,
|
| 357 |
+
alerts: List[Dict[str, Any]],
|
| 358 |
+
gate_config: SundewGateConfig,
|
| 359 |
+
) -> None:
|
| 360 |
+
|
| 361 |
+
total = len(results)
|
| 362 |
+
|
| 363 |
+
activations = int(results["activated"].sum())
|
| 364 |
+
|
| 365 |
+
activation_rate = activations / max(total, 1)
|
| 366 |
+
|
| 367 |
+
energy_savings = max(0.0, 1.0 - activation_rate)
|
| 368 |
+
|
| 369 |
+
col_a, col_b, col_c, col_d = st.columns(4)
|
| 370 |
+
|
| 371 |
+
col_a.metric("Events", f"{total}")
|
| 372 |
+
|
| 373 |
+
col_b.metric("Heavy activations", f"{activations} ({activation_rate:.1%})")
|
| 374 |
+
|
| 375 |
+
col_c.metric("Estimated energy saved", f"{energy_savings:.1%}")
|
| 376 |
+
|
| 377 |
+
col_d.metric("Alerts", f"{len(alerts)}")
|
| 378 |
+
|
| 379 |
+
if gate_config.use_native and _HAS_SUNDEW:
|
| 380 |
+
|
| 381 |
+
st.caption(
|
| 382 |
+
"Energy savings follow 1 − activation rate. With native Sundew gating we target "
|
| 383 |
+
f"≈{gate_config.target_activation:.0%} activations, so savings approach "
|
| 384 |
+
f"{1 - gate_config.target_activation:.0%}."
|
| 385 |
+
)
|
| 386 |
+
|
| 387 |
+
else:
|
| 388 |
+
|
| 389 |
+
st.warning(
|
| 390 |
+
"Fallback gate active – heavy inference runs frequently, so savings mirror the observed activation rate."
|
| 391 |
+
)
|
| 392 |
+
|
| 393 |
+
with st.expander("Recent alerts", expanded=False):
|
| 394 |
+
|
| 395 |
+
if alerts:
|
| 396 |
+
|
| 397 |
+
st.table(pd.DataFrame(alerts).tail(10))
|
| 398 |
+
|
| 399 |
+
else:
|
| 400 |
+
|
| 401 |
+
st.info("No high-risk alerts in this window.")
|
| 402 |
+
|
| 403 |
+
st.area_chart(results.set_index("timestamp")["glucose_mgdl"], height=220)
|
| 404 |
+
|
| 405 |
+
|
| 406 |
+
def render_treatment_plan(medications: Dict[str, Any], next_visit: str) -> None:
|
| 407 |
+
"""Display medication plan guidance within the treatment tab."""
|
| 408 |
+
st.subheader("Full-cycle treatment support")
|
| 409 |
+
st.write(
|
| 410 |
+
"Upload or edit medication schedules, insulin titration guidance, and clinician notes."
|
| 411 |
+
)
|
| 412 |
+
st.json(medications, expanded=False)
|
| 413 |
+
st.caption(f"Next scheduled review: {next_visit}")
|
| 414 |
+
|
| 415 |
+
|
| 416 |
+
def render_lifestyle_support(results: pd.DataFrame) -> None:
|
| 417 |
+
|
| 418 |
+
st.subheader("Lifestyle & wellbeing")
|
| 419 |
+
|
| 420 |
+
recent = results.tail(96).copy()
|
| 421 |
+
|
| 422 |
+
avg_glucose = recent["glucose_mgdl"].mean()
|
| 423 |
+
|
| 424 |
+
active_minutes = int((recent["activity_factor"] > 0.4).sum() * 5)
|
| 425 |
+
|
| 426 |
+
col1, col2 = st.columns(2)
|
| 427 |
+
|
| 428 |
+
col1.metric("Average glucose (8h)", f"{avg_glucose:.1f} mg/dL")
|
| 429 |
+
|
| 430 |
+
col2.metric("Active minutes", f"{active_minutes} min")
|
| 431 |
+
|
| 432 |
+
st.markdown(
|
| 433 |
+
"""
|
| 434 |
+
|
| 435 |
+
|
| 436 |
+
|
| 437 |
+
|
| 438 |
+
|
| 439 |
+
- Aim for gentle movement every hour you are awake.
|
| 440 |
+
|
| 441 |
+
|
| 442 |
+
|
| 443 |
+
|
| 444 |
+
|
| 445 |
+
- Pair carbohydrates with protein/fiber to smooth spikes.
|
| 446 |
+
|
| 447 |
+
|
| 448 |
+
|
| 449 |
+
|
| 450 |
+
|
| 451 |
+
- Sleep flagged recently? Try 10-minute breathing before bed.
|
| 452 |
+
|
| 453 |
+
|
| 454 |
+
|
| 455 |
+
|
| 456 |
+
|
| 457 |
+
- Journal one gratitude moment—stress strongly shapes risk.
|
| 458 |
+
|
| 459 |
+
|
| 460 |
+
|
| 461 |
+
|
| 462 |
+
|
| 463 |
+
"""
|
| 464 |
+
)
|
| 465 |
+
|
| 466 |
+
|
| 467 |
+
def render_community_actions() -> Dict[str, List[str]]:
|
| 468 |
+
|
| 469 |
+
st.subheader("Community impact")
|
| 470 |
+
|
| 471 |
+
st.write(
|
| 472 |
+
"Invite families, caregivers, and clinics to the commons. Set up alerts, shared logs, and outreach."
|
| 473 |
+
)
|
| 474 |
+
|
| 475 |
+
contact_list = [
|
| 476 |
+
"SMS: +233-200-000-111",
|
| 477 |
+
"WhatsApp: Care Circle Group",
|
| 478 |
+
"Clinic portal: sundew.health/community",
|
| 479 |
+
]
|
| 480 |
+
|
| 481 |
+
st.table(pd.DataFrame({"Support channel": contact_list}))
|
| 482 |
+
|
| 483 |
+
return {
|
| 484 |
+
"Desired partners": ["Rural clinics", "Youth ambassadors", "Nutrition co-ops"],
|
| 485 |
+
"Needs": ["Smartphone grants", "Solar charging kits", "Translation volunteers"],
|
| 486 |
+
}
|
| 487 |
+
|
| 488 |
+
|
| 489 |
+
def render_telemetry(results: pd.DataFrame, telemetry: List[Dict[str, Any]]) -> None:
|
| 490 |
+
"""Allow operators to export telemetry and inspect recent events."""
|
| 491 |
+
st.subheader("Telemetry & export")
|
| 492 |
+
st.write(
|
| 493 |
+
"Download event-level telemetry for validation, research, or regulatory reporting."
|
| 494 |
+
)
|
| 495 |
+
st.caption(
|
| 496 |
+
"Energy savings are computed as 1 minus the observed activation rate. When the gate stays mostly open, savings naturally trend toward zero."
|
| 497 |
+
)
|
| 498 |
+
json_payload = json.dumps(telemetry, default=str, indent=2)
|
| 499 |
+
st.download_button(
|
| 500 |
+
label="Download telemetry (JSON)",
|
| 501 |
+
data=json_payload,
|
| 502 |
+
file_name="sundew_diabetes_telemetry.json",
|
| 503 |
+
mime="application/json",
|
| 504 |
+
)
|
| 505 |
+
st.dataframe(results.tail(100), use_container_width=True)
|
| 506 |
+
|
| 507 |
+
|
| 508 |
+
def main() -> None:
|
| 509 |
+
"""Streamlit entry point for the Sundew diabetes commons demo."""
|
| 510 |
+
st.set_page_config(
|
| 511 |
+
page_title="Sundew Diabetes Commons",
|
| 512 |
+
layout="wide",
|
| 513 |
+
page_icon="🕊",
|
| 514 |
+
)
|
| 515 |
+
st.title("Sundew Diabetes Commons")
|
| 516 |
+
st.caption(
|
| 517 |
+
"Open, compassionate diabetes care—monitoring, treatment, lifestyle, community."
|
| 518 |
+
)
|
| 519 |
+
|
| 520 |
+
st.sidebar.header("Load data")
|
| 521 |
+
uploaded = st.sidebar.file_uploader("CGM / diary CSV", type=["csv"])
|
| 522 |
+
use_example = st.sidebar.checkbox("Use synthetic example", value=True)
|
| 523 |
+
|
| 524 |
+
st.sidebar.header("Sundew configuration")
|
| 525 |
+
use_native = st.sidebar.checkbox(
|
| 526 |
+
"Use native Sundew gating",
|
| 527 |
+
value=_HAS_SUNDEW,
|
| 528 |
+
help="Disable to demo the lightweight fallback gate only.",
|
| 529 |
+
)
|
| 530 |
+
target_activation = st.sidebar.slider("Target activation", 0.05, 0.90, 0.22, 0.01)
|
| 531 |
+
temperature = st.sidebar.slider("Gate temperature", 0.02, 0.50, 0.08, 0.01)
|
| 532 |
+
mode = st.sidebar.selectbox(
|
| 533 |
+
"Preset", ["tuned_v2", "conservative", "aggressive", "auto_tuned"], index=0
|
| 534 |
+
)
|
| 535 |
+
|
| 536 |
+
if uploaded is not None:
|
| 537 |
+
df = pd.read_csv(uploaded)
|
| 538 |
+
elif use_example:
|
| 539 |
+
df = load_example_dataset()
|
| 540 |
+
else:
|
| 541 |
+
st.info("Upload a CSV file or enable the synthetic example to continue.")
|
| 542 |
+
st.stop()
|
| 543 |
+
|
| 544 |
+
features = compute_features(df)
|
| 545 |
+
model = train_simple_model(features)
|
| 546 |
+
|
| 547 |
+
gate_config = SundewGateConfig(
|
| 548 |
+
target_activation=target_activation,
|
| 549 |
+
temperature=temperature,
|
| 550 |
+
mode=mode,
|
| 551 |
+
use_native=use_native,
|
| 552 |
+
)
|
| 553 |
+
gate = AdaptiveGate(gate_config)
|
| 554 |
+
|
| 555 |
+
telemetry: List[Dict[str, Any]] = []
|
| 556 |
+
records: List[Dict[str, Any]] = []
|
| 557 |
+
alerts: List[Dict[str, Any]] = []
|
| 558 |
+
|
| 559 |
+
total_events = len(features)
|
| 560 |
+
progress = st.progress(0.0)
|
| 561 |
+
status = st.empty()
|
| 562 |
+
|
| 563 |
+
for idx, row in enumerate(features.itertuples(index=False), start=1):
|
| 564 |
+
event = row._asdict()
|
| 565 |
+
score = lightweight_score(pd.Series(event))
|
| 566 |
+
should_run = gate.decide(score)
|
| 567 |
+
risk_proba: Optional[float] = None
|
| 568 |
+
|
| 569 |
+
if should_run and model is not None:
|
| 570 |
+
sample_df = pd.DataFrame(
|
| 571 |
+
[
|
| 572 |
+
[
|
| 573 |
+
event["glucose_mgdl"],
|
| 574 |
+
event["roc_mgdl_min"],
|
| 575 |
+
event["iob_proxy"],
|
| 576 |
+
event["cob_proxy"],
|
| 577 |
+
event["activity_factor"],
|
| 578 |
+
event["variability"],
|
| 579 |
+
]
|
| 580 |
+
],
|
| 581 |
+
columns=[
|
| 582 |
+
"glucose_mgdl",
|
| 583 |
+
"roc_mgdl_min",
|
| 584 |
+
"iob_proxy",
|
| 585 |
+
"cob_proxy",
|
| 586 |
+
"activity_factor",
|
| 587 |
+
"variability",
|
| 588 |
+
],
|
| 589 |
+
)
|
| 590 |
+
try:
|
| 591 |
+
risk_proba = float(model.predict_proba(sample_df)[0, 1]) # type: ignore[index]
|
| 592 |
+
except Exception as exc:
|
| 593 |
+
LOGGER.debug("Risk model inference failed: %s", exc)
|
| 594 |
+
risk_proba = None
|
| 595 |
+
|
| 596 |
+
if risk_proba is not None and risk_proba >= 0.6:
|
| 597 |
+
alerts.append(
|
| 598 |
+
{
|
| 599 |
+
"timestamp": event["timestamp"],
|
| 600 |
+
"glucose": event["glucose_mgdl"],
|
| 601 |
+
"risk": risk_proba,
|
| 602 |
+
"message": "Check CGM, hydrate, plan balanced snack/insulin",
|
| 603 |
+
}
|
| 604 |
+
)
|
| 605 |
+
|
| 606 |
+
records.append(
|
| 607 |
+
{
|
| 608 |
+
"timestamp": event["timestamp"],
|
| 609 |
+
"glucose_mgdl": event["glucose_mgdl"],
|
| 610 |
+
"roc_mgdl_min": event["roc_mgdl_min"],
|
| 611 |
+
"deviation": event["deviation"],
|
| 612 |
+
"iob_proxy": event["iob_proxy"],
|
| 613 |
+
"cob_proxy": event["cob_proxy"],
|
| 614 |
+
"variability": event["variability"],
|
| 615 |
+
"activity_factor": event["activity_factor"],
|
| 616 |
+
"score": score,
|
| 617 |
+
"activated": should_run,
|
| 618 |
+
"risk_proba": risk_proba,
|
| 619 |
+
}
|
| 620 |
+
)
|
| 621 |
+
|
| 622 |
+
telemetry.append(
|
| 623 |
+
{
|
| 624 |
+
"timestamp": str(event["timestamp"]),
|
| 625 |
+
"score": score,
|
| 626 |
+
"activated": should_run,
|
| 627 |
+
"risk_proba": risk_proba,
|
| 628 |
+
}
|
| 629 |
+
)
|
| 630 |
+
|
| 631 |
+
progress.progress(idx / max(total_events, 1))
|
| 632 |
+
status.text(f"Processing event {idx}/{total_events}")
|
| 633 |
+
|
| 634 |
+
progress.empty()
|
| 635 |
+
status.empty()
|
| 636 |
+
|
| 637 |
+
results = pd.DataFrame(records)
|
| 638 |
+
tabs = st.tabs(["Overview", "Treatment", "Lifestyle", "Community", "Telemetry"])
|
| 639 |
+
|
| 640 |
+
with tabs[0]:
|
| 641 |
+
render_overview(results, alerts, gate_config)
|
| 642 |
+
|
| 643 |
+
with tabs[1]:
|
| 644 |
+
default_plan = {
|
| 645 |
+
"Insulin": {
|
| 646 |
+
"Basal": "14u glargine at 21:00",
|
| 647 |
+
"Bolus": "1u per 10g carbs + correction 1u per 40 mg/dL over 140",
|
| 648 |
+
},
|
| 649 |
+
"Oral medications": {
|
| 650 |
+
"Metformin": "500mg breakfast + 500mg dinner",
|
| 651 |
+
"Empagliflozin": "10mg once daily (if eGFR > 45)",
|
| 652 |
+
},
|
| 653 |
+
"Monitoring": [
|
| 654 |
+
"CGM sensor change every 10 days",
|
| 655 |
+
"Morning fasted CGM calibration",
|
| 656 |
+
"Weekly telehealth coaching",
|
| 657 |
+
"Quarterly in-person clinician review",
|
| 658 |
+
],
|
| 659 |
+
"Safety plan": [
|
| 660 |
+
"Carry glucose tabs + glucagon kit",
|
| 661 |
+
"Emergency contact: +233-200-000-888",
|
| 662 |
+
],
|
| 663 |
+
"Lifestyle": [
|
| 664 |
+
"30 min brisk walk 5x/week",
|
| 665 |
+
"Bedtime snack if glucose < 110 mg/dL",
|
| 666 |
+
"Hydrate 2L water daily unless contraindicated",
|
| 667 |
+
],
|
| 668 |
+
}
|
| 669 |
+
st.caption(
|
| 670 |
+
"Upload or edit schedules, medication titration guidance, and clinician notes."
|
| 671 |
+
)
|
| 672 |
+
uploaded_plan = st.file_uploader(
|
| 673 |
+
"Optional plan JSON", type=["json"], key="plan_uploader"
|
| 674 |
+
)
|
| 675 |
+
plan_text = st.text_area(
|
| 676 |
+
"Edit plan JSON",
|
| 677 |
+
json.dumps(default_plan, indent=2),
|
| 678 |
+
height=240,
|
| 679 |
+
key="plan_editor",
|
| 680 |
+
)
|
| 681 |
+
|
| 682 |
+
plan_data = default_plan
|
| 683 |
+
if uploaded_plan is not None:
|
| 684 |
+
try:
|
| 685 |
+
plan_data = json.load(uploaded_plan)
|
| 686 |
+
except Exception as exc:
|
| 687 |
+
st.error(f"Could not parse uploaded plan JSON: {exc}")
|
| 688 |
+
plan_data = default_plan
|
| 689 |
+
else:
|
| 690 |
+
try:
|
| 691 |
+
plan_data = json.loads(plan_text)
|
| 692 |
+
except Exception as exc:
|
| 693 |
+
st.warning(
|
| 694 |
+
f"Using default plan because text could not be parsed: {exc}"
|
| 695 |
+
)
|
| 696 |
+
plan_data = default_plan
|
| 697 |
+
|
| 698 |
+
next_visit = (datetime.utcnow() + timedelta(days=30)).strftime(
|
| 699 |
+
"%Y-%m-%d (telehealth)"
|
| 700 |
+
)
|
| 701 |
+
render_treatment_plan(plan_data, next_visit=next_visit)
|
| 702 |
+
|
| 703 |
+
with tabs[2]:
|
| 704 |
+
render_lifestyle_support(results)
|
| 705 |
+
|
| 706 |
+
with tabs[3]:
|
| 707 |
+
community_items = render_community_actions()
|
| 708 |
+
st.json(community_items, expanded=False)
|
| 709 |
+
|
| 710 |
+
with tabs[4]:
|
| 711 |
+
render_telemetry(results, telemetry)
|
| 712 |
+
|
| 713 |
+
st.sidebar.markdown("---")
|
| 714 |
+
status_text = (
|
| 715 |
+
"native gating"
|
| 716 |
+
if gate_config.use_native and gate.sundew is not None
|
| 717 |
+
else "fallback gate"
|
| 718 |
+
)
|
| 719 |
+
st.sidebar.caption(f"Sundew status: {status_text}")
|
| 720 |
+
|
| 721 |
+
|
| 722 |
+
if __name__ == "__main__":
|
| 723 |
+
|
| 724 |
+
main()
|