Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,12 +5,12 @@ from pathlib import Path
|
|
| 5 |
import gradio as gr
|
| 6 |
|
| 7 |
# ============================================================
|
| 8 |
-
# Paths
|
| 9 |
# ============================================================
|
| 10 |
|
| 11 |
ROOT = Path(__file__).resolve().parent
|
| 12 |
|
| 13 |
-
DOWN_ROOT = ROOT / "
|
| 14 |
STRANGE_ROOT = ROOT / "Strange"
|
| 15 |
|
| 16 |
DOWN_GRAPHICS = DOWN_ROOT / "graphics"
|
|
@@ -22,29 +22,34 @@ STRANGE_GRAPHICS = STRANGE_ROOT / "graphics"
|
|
| 22 |
# ============================================================
|
| 23 |
|
| 24 |
def _clean_pngs(folder: Path):
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
| 27 |
f.unlink()
|
| 28 |
-
|
| 29 |
-
|
| 30 |
|
| 31 |
|
| 32 |
def _collect_pngs(folder: Path):
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
|
| 36 |
# ============================================================
|
| 37 |
# DOWN (Unified: Down + AntiDown)
|
| 38 |
# ============================================================
|
| 39 |
|
| 40 |
-
def run_down_all():
|
| 41 |
run_all = DOWN_ROOT / "run_all.py"
|
| 42 |
if not run_all.exists():
|
| 43 |
-
raise RuntimeError("
|
| 44 |
|
| 45 |
_clean_pngs(DOWN_GRAPHICS)
|
| 46 |
|
| 47 |
-
cmd = [sys.executable,
|
| 48 |
|
| 49 |
subprocess.run(
|
| 50 |
cmd,
|
|
@@ -54,26 +59,28 @@ def run_down_all():
|
|
| 54 |
)
|
| 55 |
|
| 56 |
images = _collect_pngs(DOWN_GRAPHICS)
|
| 57 |
-
|
| 58 |
meta = {
|
| 59 |
"status": "completed",
|
| 60 |
"pipeline": "DOWN + AntiDown",
|
|
|
|
| 61 |
"graphics_count": len(images),
|
| 62 |
"graphics_dir": str(DOWN_GRAPHICS),
|
| 63 |
}
|
| 64 |
-
|
| 65 |
return meta, images
|
| 66 |
|
|
|
|
|
|
|
| 67 |
# STRANGE (Unified: Strange + AntiStrange)
|
|
|
|
| 68 |
|
| 69 |
def run_strange_all():
|
| 70 |
run_all = STRANGE_ROOT / "run_all.py"
|
| 71 |
if not run_all.exists():
|
| 72 |
-
raise RuntimeError("
|
| 73 |
|
| 74 |
_clean_pngs(STRANGE_GRAPHICS)
|
| 75 |
|
| 76 |
-
cmd = [sys.executable,
|
| 77 |
|
| 78 |
subprocess.run(
|
| 79 |
cmd,
|
|
@@ -83,14 +90,12 @@ def run_strange_all():
|
|
| 83 |
)
|
| 84 |
|
| 85 |
images = _collect_pngs(STRANGE_GRAPHICS)
|
| 86 |
-
|
| 87 |
meta = {
|
| 88 |
"status": "completed",
|
| 89 |
"pipeline": "STRANGE + AntiStrange",
|
| 90 |
"graphics_count": len(images),
|
| 91 |
"graphics_dir": str(STRANGE_GRAPHICS),
|
| 92 |
}
|
| 93 |
-
|
| 94 |
return meta, images
|
| 95 |
|
| 96 |
|
|
@@ -99,14 +104,10 @@ def run_strange_all():
|
|
| 99 |
# ============================================================
|
| 100 |
|
| 101 |
def build_ui():
|
| 102 |
-
with gr.Blocks(
|
| 103 |
-
title="TwoQuarks — QuarksLab",
|
| 104 |
-
) as demo:
|
| 105 |
-
|
| 106 |
gr.Markdown(
|
| 107 |
"""
|
| 108 |
-
# TwoQuarks • QuarksLab
|
| 109 |
-
|
| 110 |
**Run Models. Real artifacts. Real Models.**
|
| 111 |
"""
|
| 112 |
)
|
|
@@ -117,8 +118,9 @@ def build_ui():
|
|
| 117 |
gr.Markdown("## DOWN / AntiDown")
|
| 118 |
gr.Markdown(
|
| 119 |
"""
|
| 120 |
-
The Down / AntiDown models are reinforcement learning agents
|
| 121 |
-
designed to expose and analyze failure modes under deceptive reward conditions.
|
|
|
|
| 122 |
)
|
| 123 |
|
| 124 |
down_eps = gr.Slider(
|
|
@@ -130,13 +132,8 @@ designed to expose and analyze failure modes under deceptive reward conditions."
|
|
| 130 |
)
|
| 131 |
|
| 132 |
run_down_btn = gr.Button("Run DOWN Model")
|
| 133 |
-
|
| 134 |
down_meta = gr.JSON(label="Run status")
|
| 135 |
-
down_gallery = gr.Gallery(
|
| 136 |
-
label="Generated plots",
|
| 137 |
-
columns=2,
|
| 138 |
-
height="auto",
|
| 139 |
-
)
|
| 140 |
|
| 141 |
run_down_btn.click(
|
| 142 |
fn=run_down_all,
|
|
@@ -152,19 +149,14 @@ designed to expose and analyze failure modes under deceptive reward conditions."
|
|
| 152 |
gr.Markdown("## STRANGE / AntiStrange")
|
| 153 |
gr.Markdown(
|
| 154 |
"""
|
| 155 |
-
Strange / AntiStrange are reinforcement learning agents
|
| 156 |
-
designed to study failure under hidden regime shifts and phase transitions.
|
| 157 |
"""
|
| 158 |
)
|
| 159 |
|
| 160 |
run_strange_btn = gr.Button("Run STRANGE Model")
|
| 161 |
-
|
| 162 |
strange_meta = gr.JSON(label="Run status")
|
| 163 |
-
strange_gallery = gr.Gallery(
|
| 164 |
-
label="Generated plots",
|
| 165 |
-
columns=2,
|
| 166 |
-
height="auto",
|
| 167 |
-
)
|
| 168 |
|
| 169 |
run_strange_btn.click(
|
| 170 |
fn=run_strange_all,
|
|
@@ -176,7 +168,7 @@ designed to study failure under hidden regime shifts and phase transitions.
|
|
| 176 |
"""
|
| 177 |
---
|
| 178 |
### Notes:
|
| 179 |
-
- This lab, its models & the TwoQuarks website,
|
| 180 |
are developed end to end by Jaime Ledesma.
|
| 181 |
- Gradio does not import or orchestrate internal model logic.
|
| 182 |
- All visualizations are the result produced by the model.
|
|
|
|
| 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"
|
|
|
|
| 22 |
# ============================================================
|
| 23 |
|
| 24 |
def _clean_pngs(folder: Path):
|
| 25 |
+
folder.mkdir(parents=True, exist_ok=True)
|
| 26 |
+
# Clean recursively to handle "graphics/graphics"
|
| 27 |
+
for f in folder.rglob("*.png"):
|
| 28 |
+
try:
|
| 29 |
f.unlink()
|
| 30 |
+
except Exception:
|
| 31 |
+
pass
|
| 32 |
|
| 33 |
|
| 34 |
def _collect_pngs(folder: Path):
|
| 35 |
+
if not folder.exists():
|
| 36 |
+
return []
|
| 37 |
+
# Collect recursively to handle nested folders
|
| 38 |
+
return sorted(str(p) for p in folder.rglob("*.png"))
|
| 39 |
|
| 40 |
|
| 41 |
# ============================================================
|
| 42 |
# DOWN (Unified: Down + AntiDown)
|
| 43 |
# ============================================================
|
| 44 |
|
| 45 |
+
def run_down_all(episodes: int):
|
| 46 |
run_all = DOWN_ROOT / "run_all.py"
|
| 47 |
if not run_all.exists():
|
| 48 |
+
raise RuntimeError(f"{run_all} not found (check folder name: must be 'Down/')")
|
| 49 |
|
| 50 |
_clean_pngs(DOWN_GRAPHICS)
|
| 51 |
|
| 52 |
+
cmd = [sys.executable, str(run_all), "--episodes", str(int(episodes))]
|
| 53 |
|
| 54 |
subprocess.run(
|
| 55 |
cmd,
|
|
|
|
| 59 |
)
|
| 60 |
|
| 61 |
images = _collect_pngs(DOWN_GRAPHICS)
|
|
|
|
| 62 |
meta = {
|
| 63 |
"status": "completed",
|
| 64 |
"pipeline": "DOWN + AntiDown",
|
| 65 |
+
"episodes": int(episodes),
|
| 66 |
"graphics_count": len(images),
|
| 67 |
"graphics_dir": str(DOWN_GRAPHICS),
|
| 68 |
}
|
|
|
|
| 69 |
return meta, images
|
| 70 |
|
| 71 |
+
|
| 72 |
+
# ============================================================
|
| 73 |
# STRANGE (Unified: Strange + AntiStrange)
|
| 74 |
+
# ============================================================
|
| 75 |
|
| 76 |
def run_strange_all():
|
| 77 |
run_all = STRANGE_ROOT / "run_all.py"
|
| 78 |
if not run_all.exists():
|
| 79 |
+
raise RuntimeError(f"{run_all} not found (check folder name: must be 'Strange/')")
|
| 80 |
|
| 81 |
_clean_pngs(STRANGE_GRAPHICS)
|
| 82 |
|
| 83 |
+
cmd = [sys.executable, str(run_all)]
|
| 84 |
|
| 85 |
subprocess.run(
|
| 86 |
cmd,
|
|
|
|
| 90 |
)
|
| 91 |
|
| 92 |
images = _collect_pngs(STRANGE_GRAPHICS)
|
|
|
|
| 93 |
meta = {
|
| 94 |
"status": "completed",
|
| 95 |
"pipeline": "STRANGE + AntiStrange",
|
| 96 |
"graphics_count": len(images),
|
| 97 |
"graphics_dir": str(STRANGE_GRAPHICS),
|
| 98 |
}
|
|
|
|
| 99 |
return meta, images
|
| 100 |
|
| 101 |
|
|
|
|
| 104 |
# ============================================================
|
| 105 |
|
| 106 |
def build_ui():
|
| 107 |
+
with gr.Blocks(title="TwoQuarks — QuarksLab") as demo:
|
|
|
|
|
|
|
|
|
|
| 108 |
gr.Markdown(
|
| 109 |
"""
|
| 110 |
+
# TwoQuarks • QuarksLab
|
|
|
|
| 111 |
**Run Models. Real artifacts. Real Models.**
|
| 112 |
"""
|
| 113 |
)
|
|
|
|
| 118 |
gr.Markdown("## DOWN / AntiDown")
|
| 119 |
gr.Markdown(
|
| 120 |
"""
|
| 121 |
+
The Down / AntiDown models are reinforcement learning agents
|
| 122 |
+
designed to expose and analyze failure modes under deceptive reward conditions.
|
| 123 |
+
"""
|
| 124 |
)
|
| 125 |
|
| 126 |
down_eps = gr.Slider(
|
|
|
|
| 132 |
)
|
| 133 |
|
| 134 |
run_down_btn = gr.Button("Run DOWN Model")
|
|
|
|
| 135 |
down_meta = gr.JSON(label="Run status")
|
| 136 |
+
down_gallery = gr.Gallery(label="Generated plots", columns=2, height="auto")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
|
| 138 |
run_down_btn.click(
|
| 139 |
fn=run_down_all,
|
|
|
|
| 149 |
gr.Markdown("## STRANGE / AntiStrange")
|
| 150 |
gr.Markdown(
|
| 151 |
"""
|
| 152 |
+
Strange / AntiStrange are reinforcement learning agents
|
| 153 |
+
designed to study failure under hidden regime shifts and phase transitions.
|
| 154 |
"""
|
| 155 |
)
|
| 156 |
|
| 157 |
run_strange_btn = gr.Button("Run STRANGE Model")
|
|
|
|
| 158 |
strange_meta = gr.JSON(label="Run status")
|
| 159 |
+
strange_gallery = gr.Gallery(label="Generated plots", columns=2, height="auto")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
run_strange_btn.click(
|
| 162 |
fn=run_strange_all,
|
|
|
|
| 168 |
"""
|
| 169 |
---
|
| 170 |
### Notes:
|
| 171 |
+
- This lab, its models & the TwoQuarks website,
|
| 172 |
are developed end to end by Jaime Ledesma.
|
| 173 |
- Gradio does not import or orchestrate internal model logic.
|
| 174 |
- All visualizations are the result produced by the model.
|