Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,361 +1,365 @@
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import subprocess
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
import gradio as gr
|
| 6 |
+
|
| 7 |
+
# ============================================================
|
| 8 |
+
# Paths (Linux is case-sensitive!)
|
| 9 |
+
# ============================================================
|
| 10 |
+
|
| 11 |
+
ROOT = Path(__file__).resolve().parent
|
| 12 |
+
|
| 13 |
+
DOWN_ROOT = ROOT / "Down"
|
| 14 |
+
STRANGE_ROOT = ROOT / "Strange"
|
| 15 |
+
|
| 16 |
+
DOWN_GRAPHICS = DOWN_ROOT / "graphics"
|
| 17 |
+
STRANGE_GRAPHICS = STRANGE_ROOT / "graphics"
|
| 18 |
+
|
| 19 |
+
DOWN_RESULTS = DOWN_ROOT / "results"
|
| 20 |
+
STRANGE_RESULTS = STRANGE_ROOT / "results"
|
| 21 |
+
|
| 22 |
+
STYLE_PATH = ROOT / "style.css"
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
# ============================================================
|
| 26 |
+
# CSS + JS (canvas + menu)
|
| 27 |
+
# ============================================================
|
| 28 |
+
|
| 29 |
+
CSS = STYLE_PATH.read_text(encoding="utf-8") if STYLE_PATH.exists() else ""
|
| 30 |
+
|
| 31 |
+
JS = r"""
|
| 32 |
+
() => {
|
| 33 |
+
// prevent double init (Gradio can re-render)
|
| 34 |
+
if (window.__tq_inited) return;
|
| 35 |
+
window.__tq_inited = true;
|
| 36 |
+
|
| 37 |
+
// --- Menu toggle ---
|
| 38 |
+
const btn = document.getElementById("tqMenuBtn");
|
| 39 |
+
const menu = document.getElementById("tqMenu");
|
| 40 |
+
if (btn && menu) {
|
| 41 |
+
btn.addEventListener("click", () => menu.classList.toggle("open"));
|
| 42 |
+
document.addEventListener("click", (e) => {
|
| 43 |
+
if (!menu.contains(e.target) && !btn.contains(e.target)) {
|
| 44 |
+
menu.classList.remove("open");
|
| 45 |
+
}
|
| 46 |
+
});
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
// --- Starfield canvas ---
|
| 50 |
+
const c = document.getElementById("quantumField");
|
| 51 |
+
if (!c) return;
|
| 52 |
+
const ctx = c.getContext("2d");
|
| 53 |
+
if (!ctx) return;
|
| 54 |
+
|
| 55 |
+
let w = 0, h = 0;
|
| 56 |
+
const stars = [];
|
| 57 |
+
const N = 170;
|
| 58 |
+
|
| 59 |
+
function resize() {
|
| 60 |
+
w = c.width = window.innerWidth;
|
| 61 |
+
h = c.height = window.innerHeight;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
function seed() {
|
| 65 |
+
stars.length = 0;
|
| 66 |
+
for (let i = 0; i < N; i++) {
|
| 67 |
+
stars.push({
|
| 68 |
+
x: Math.random() * w,
|
| 69 |
+
y: Math.random() * h,
|
| 70 |
+
z: 0.2 + Math.random() * 0.8,
|
| 71 |
+
v: 0.15 + Math.random() * 0.55,
|
| 72 |
+
});
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
function tick() {
|
| 77 |
+
ctx.clearRect(0, 0, w, h);
|
| 78 |
+
|
| 79 |
+
// subtle vignette
|
| 80 |
+
const g = ctx.createRadialGradient(w/2, h/2, 10, w/2, h/2, Math.max(w,h)/1.1);
|
| 81 |
+
g.addColorStop(0, "rgba(0,0,0,0)");
|
| 82 |
+
g.addColorStop(1, "rgba(0,0,0,0.55)");
|
| 83 |
+
ctx.fillStyle = g;
|
| 84 |
+
ctx.fillRect(0, 0, w, h);
|
| 85 |
+
|
| 86 |
+
ctx.globalAlpha = 0.9;
|
| 87 |
+
|
| 88 |
+
for (const s of stars) {
|
| 89 |
+
s.y += s.v * (1.0 + (1.0 - s.z));
|
| 90 |
+
if (s.y > h + 10) { s.y = -10; s.x = Math.random() * w; }
|
| 91 |
+
|
| 92 |
+
const r = 0.6 + 1.6 * (1.0 - s.z);
|
| 93 |
+
ctx.fillStyle = "rgba(255,255,255,0.75)";
|
| 94 |
+
ctx.beginPath();
|
| 95 |
+
ctx.arc(s.x, s.y, r, 0, Math.PI * 2);
|
| 96 |
+
ctx.fill();
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
requestAnimationFrame(tick);
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
resize();
|
| 103 |
+
seed();
|
| 104 |
+
window.addEventListener("resize", () => { resize(); seed(); });
|
| 105 |
+
tick();
|
| 106 |
+
}
|
| 107 |
+
"""
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
# ============================================================
|
| 111 |
+
# Helpers
|
| 112 |
+
# ============================================================
|
| 113 |
+
|
| 114 |
+
def _clean_pngs(folder: Path):
|
| 115 |
+
folder.mkdir(parents=True, exist_ok=True)
|
| 116 |
+
for f in folder.rglob("*.png"):
|
| 117 |
+
try:
|
| 118 |
+
f.unlink()
|
| 119 |
+
except Exception:
|
| 120 |
+
pass
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def _collect_pngs(folder: Path):
|
| 124 |
+
if not folder.exists():
|
| 125 |
+
return []
|
| 126 |
+
return sorted(str(p) for p in folder.rglob("*.png"))
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
def _run_capture(cmd, cwd: Path, env: dict):
|
| 130 |
+
"""
|
| 131 |
+
Run a subprocess and capture stdout/stderr.
|
| 132 |
+
If it fails, raise a RuntimeError containing the logs so Gradio shows it.
|
| 133 |
+
"""
|
| 134 |
+
result = subprocess.run(
|
| 135 |
+
cmd,
|
| 136 |
+
cwd=str(cwd),
|
| 137 |
+
env=env,
|
| 138 |
+
capture_output=True,
|
| 139 |
+
text=True,
|
| 140 |
+
)
|
| 141 |
+
if result.returncode != 0:
|
| 142 |
+
raise RuntimeError(
|
| 143 |
+
"Subprocess failed\n"
|
| 144 |
+
f"CMD: {' '.join(map(str, cmd))}\n"
|
| 145 |
+
f"CWD: {cwd}\n\n"
|
| 146 |
+
f"STDOUT:\n{result.stdout}\n"
|
| 147 |
+
f"STDERR:\n{result.stderr}"
|
| 148 |
+
)
|
| 149 |
+
return result.stdout, result.stderr
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
# ============================================================
|
| 153 |
+
# DOWN (Unified: Down + AntiDown)
|
| 154 |
+
# ============================================================
|
| 155 |
+
|
| 156 |
+
def run_down_all(episodes: int):
|
| 157 |
+
run_all = DOWN_ROOT / "run_all.py"
|
| 158 |
+
if not run_all.exists():
|
| 159 |
+
raise RuntimeError(f"{run_all} not found (check folder name: must be 'Down/')")
|
| 160 |
+
|
| 161 |
+
DOWN_GRAPHICS.mkdir(parents=True, exist_ok=True)
|
| 162 |
+
DOWN_RESULTS.mkdir(parents=True, exist_ok=True)
|
| 163 |
+
|
| 164 |
+
_clean_pngs(DOWN_GRAPHICS)
|
| 165 |
+
|
| 166 |
+
env = os.environ.copy()
|
| 167 |
+
env["TWOQUARKS_RESULTS_DIR"] = str(DOWN_RESULTS)
|
| 168 |
+
env["TWOQUARKS_GRAPHICS_DIR"] = str(DOWN_GRAPHICS)
|
| 169 |
+
|
| 170 |
+
cmd = [sys.executable, str(run_all), "--episodes", str(int(episodes))]
|
| 171 |
+
|
| 172 |
+
_run_capture(cmd, cwd=DOWN_ROOT, env=env)
|
| 173 |
+
|
| 174 |
+
images = _collect_pngs(DOWN_GRAPHICS)
|
| 175 |
+
meta = {
|
| 176 |
+
"status": "completed",
|
| 177 |
+
"pipeline": "DOWN + AntiDown",
|
| 178 |
+
"episodes_per_phase": int(episodes),
|
| 179 |
+
"graphics_count": len(images),
|
| 180 |
+
"graphics_dir": str(DOWN_GRAPHICS),
|
| 181 |
+
"results_dir": str(DOWN_RESULTS),
|
| 182 |
+
"csv_down": str(DOWN_RESULTS / "down_paradox_tabular_results.csv"),
|
| 183 |
+
"csv_antidown": str(DOWN_RESULTS / "antidown_corrupted_valley_tabular.csv"),
|
| 184 |
+
}
|
| 185 |
+
return meta, images
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
# ============================================================
|
| 189 |
+
# STRANGE (Unified: Strange + AntiStrange)
|
| 190 |
+
# ============================================================
|
| 191 |
+
|
| 192 |
+
def run_strange_all():
|
| 193 |
+
run_all = STRANGE_ROOT / "run_all.py"
|
| 194 |
+
if not run_all.exists():
|
| 195 |
+
raise RuntimeError(f"{run_all} not found (check folder name: must be 'Strange/')")
|
| 196 |
+
|
| 197 |
+
STRANGE_GRAPHICS.mkdir(parents=True, exist_ok=True)
|
| 198 |
+
STRANGE_RESULTS.mkdir(parents=True, exist_ok=True)
|
| 199 |
+
|
| 200 |
+
_clean_pngs(STRANGE_GRAPHICS)
|
| 201 |
+
|
| 202 |
+
env = os.environ.copy()
|
| 203 |
+
env["TWOQUARKS_RESULTS_DIR"] = str(STRANGE_RESULTS)
|
| 204 |
+
env["TWOQUARKS_GRAPHICS_DIR"] = str(STRANGE_GRAPHICS)
|
| 205 |
+
|
| 206 |
+
cmd = [sys.executable, str(run_all)]
|
| 207 |
+
|
| 208 |
+
_run_capture(cmd, cwd=STRANGE_ROOT, env=env)
|
| 209 |
+
|
| 210 |
+
images = _collect_pngs(STRANGE_GRAPHICS)
|
| 211 |
+
meta = {
|
| 212 |
+
"status": "completed",
|
| 213 |
+
"pipeline": "STRANGE + AntiStrange",
|
| 214 |
+
"graphics_count": len(images),
|
| 215 |
+
"graphics_dir": str(STRANGE_GRAPHICS),
|
| 216 |
+
"results_dir": str(STRANGE_RESULTS),
|
| 217 |
+
}
|
| 218 |
+
return meta, images
|
| 219 |
+
|
| 220 |
+
|
| 221 |
+
# ============================================================
|
| 222 |
+
# UI
|
| 223 |
+
# ============================================================
|
| 224 |
+
|
| 225 |
+
def build_ui():
|
| 226 |
+
with gr.Blocks(title="TwoQuarks — QuarksLab", css=CSS, js=JS) as demo:
|
| 227 |
+
|
| 228 |
+
# Inject DOM for canvas + nav
|
| 229 |
+
gr.HTML(
|
| 230 |
+
"""
|
| 231 |
+
<canvas id="quantumField"></canvas>
|
| 232 |
+
|
| 233 |
+
<nav id="tqNav">
|
| 234 |
+
<div class="nav-inner">
|
| 235 |
+
<div class="brand">TwoQuarks</div>
|
| 236 |
+
|
| 237 |
+
<div class="nav-links">
|
| 238 |
+
<a href="#down">Down</a>
|
| 239 |
+
<a href="#strange">Strange</a>
|
| 240 |
+
</div>
|
| 241 |
+
|
| 242 |
+
<div class="spacer"></div>
|
| 243 |
+
|
| 244 |
+
<div class="menu-btn" id="tqMenuBtn" aria-label="menu">
|
| 245 |
+
<span></span>
|
| 246 |
+
</div>
|
| 247 |
+
|
| 248 |
+
<div class="menu" id="tqMenu">
|
| 249 |
+
<a href="#down">DOWN / AntiDown</a>
|
| 250 |
+
<div class="sep"></div>
|
| 251 |
+
<a href="#strange">STRANGE / AntiStrange</a>
|
| 252 |
+
</div>
|
| 253 |
+
</div>
|
| 254 |
+
</nav>
|
| 255 |
+
"""
|
| 256 |
+
)
|
| 257 |
+
|
| 258 |
+
# App wrapper (needed for z-index + padding-top in your CSS)
|
| 259 |
+
with gr.Column(elem_id="tqApp"):
|
| 260 |
+
|
| 261 |
+
gr.Markdown(
|
| 262 |
+
"""
|
| 263 |
+
<div class="tq-hero">
|
| 264 |
+
<div class="brand">TwoQuarks • QuarksLab</div>
|
| 265 |
+
<div class="desc"><b>Run Models.</b> Real artifacts. Real Models.</div>
|
| 266 |
+
</div>
|
| 267 |
+
""",
|
| 268 |
+
elem_id="top",
|
| 269 |
+
)
|
| 270 |
+
|
| 271 |
+
# ----------------------------
|
| 272 |
+
# DOWN
|
| 273 |
+
# ----------------------------
|
| 274 |
+
gr.HTML('<div id="down"></div>')
|
| 275 |
+
|
| 276 |
+
gr.Markdown("## DOWN / AntiDown")
|
| 277 |
+
gr.Markdown(
|
| 278 |
+
"""
|
| 279 |
+
The Down / AntiDown models are reinforcement learning agents
|
| 280 |
+
designed to expose and analyze failure modes under deceptive reward conditions.
|
| 281 |
+
"""
|
| 282 |
+
)
|
| 283 |
+
|
| 284 |
+
down_eps = gr.Slider(
|
| 285 |
+
minimum=50,
|
| 286 |
+
maximum=500,
|
| 287 |
+
step=50,
|
| 288 |
+
value=200,
|
| 289 |
+
label="Episodes per phase",
|
| 290 |
+
)
|
| 291 |
+
|
| 292 |
+
run_down_btn = gr.Button("Run DOWN Model", elem_classes=["tq-primary"])
|
| 293 |
+
down_meta = gr.JSON(label="Run status")
|
| 294 |
+
|
| 295 |
+
# elem_id is REQUIRED for carousel CSS
|
| 296 |
+
down_gallery = gr.Gallery(
|
| 297 |
+
label="Generated plots",
|
| 298 |
+
columns=2,
|
| 299 |
+
height="auto",
|
| 300 |
+
elem_id="down_gallery",
|
| 301 |
+
)
|
| 302 |
+
|
| 303 |
+
run_down_btn.click(
|
| 304 |
+
fn=run_down_all,
|
| 305 |
+
inputs=[down_eps],
|
| 306 |
+
outputs=[down_meta, down_gallery],
|
| 307 |
+
)
|
| 308 |
+
|
| 309 |
+
gr.Markdown("---")
|
| 310 |
+
|
| 311 |
+
# ----------------------------
|
| 312 |
+
# STRANGE
|
| 313 |
+
# ----------------------------
|
| 314 |
+
gr.HTML('<div id="strange"></div>')
|
| 315 |
+
|
| 316 |
+
gr.Markdown("## STRANGE / AntiStrange")
|
| 317 |
+
gr.Markdown(
|
| 318 |
+
"""
|
| 319 |
+
Strange / AntiStrange are reinforcement learning agents
|
| 320 |
+
designed to study failure under hidden regime shifts and phase transitions.
|
| 321 |
+
"""
|
| 322 |
+
)
|
| 323 |
+
|
| 324 |
+
run_strange_btn = gr.Button("Run STRANGE Model", elem_classes=["tq-primary"])
|
| 325 |
+
strange_meta = gr.JSON(label="Run status")
|
| 326 |
+
|
| 327 |
+
strange_gallery = gr.Gallery(
|
| 328 |
+
label="Generated plots",
|
| 329 |
+
columns=2,
|
| 330 |
+
height="auto",
|
| 331 |
+
elem_id="strange_gallery",
|
| 332 |
+
)
|
| 333 |
+
|
| 334 |
+
run_strange_btn.click(
|
| 335 |
+
fn=run_strange_all,
|
| 336 |
+
inputs=[],
|
| 337 |
+
outputs=[strange_meta, strange_gallery],
|
| 338 |
+
)
|
| 339 |
+
|
| 340 |
+
gr.Markdown(
|
| 341 |
+
"""
|
| 342 |
+
---
|
| 343 |
+
### Notes:
|
| 344 |
+
- This lab, its models & the TwoQuarks website,
|
| 345 |
+
are developed end to end by Jaime Ledesma.
|
| 346 |
+
- Gradio does not import or orchestrate internal model logic.
|
| 347 |
+
- All visualizations are the result produced by the model.
|
| 348 |
+
"""
|
| 349 |
+
)
|
| 350 |
+
|
| 351 |
+
return demo
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
# ============================================================
|
| 355 |
+
# Launch
|
| 356 |
+
# ============================================================
|
| 357 |
+
|
| 358 |
+
demo = build_ui()
|
| 359 |
+
|
| 360 |
+
if __name__ == "__main__":
|
| 361 |
+
demo.launch(
|
| 362 |
+
server_name="0.0.0.0",
|
| 363 |
+
server_port=int(os.getenv("PORT", "7860")),
|
| 364 |
+
show_api=False,
|
| 365 |
+
)
|