Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -17,7 +17,60 @@ LOG_FILE = "./training.log"
|
|
| 17 |
DONE_FILE = "./training_done.txt"
|
| 18 |
PID_FILE = "./training.pid"
|
| 19 |
RESULTS_FILE = f"{PLOTS_DIR}/results.json"
|
|
|
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def is_training_alive():
|
| 23 |
if not os.path.exists(PID_FILE):
|
|
@@ -51,19 +104,146 @@ def _run():
|
|
| 51 |
pass
|
| 52 |
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
st.set_page_config(page_title="SecureReview Trainer", layout="wide")
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
st.markdown(
|
| 57 |
-
"Trains via GRPO on the live
|
| 58 |
-
"Reward comes from
|
| 59 |
)
|
| 60 |
|
| 61 |
done = os.path.exists(DONE_FILE)
|
| 62 |
log_present = os.path.exists(LOG_FILE)
|
| 63 |
training_alive = is_training_alive()
|
| 64 |
-
|
| 65 |
-
# Resume detection: if log file exists and not marked done, treat as ongoing
|
| 66 |
-
ongoing = log_present and not done
|
| 67 |
|
| 68 |
if not ongoing and not done:
|
| 69 |
if st.button("▶ Run Training", type="primary"):
|
|
|
|
| 17 |
DONE_FILE = "./training_done.txt"
|
| 18 |
PID_FILE = "./training.pid"
|
| 19 |
RESULTS_FILE = f"{PLOTS_DIR}/results.json"
|
| 20 |
+
TASK_ID_FILE = "./.task_id"
|
| 21 |
|
| 22 |
+
# ---------------------------------------------------------------------------
|
| 23 |
+
# Trainer hub config — same across all 3 trainer Spaces, the active task
|
| 24 |
+
# is selected by the contents of `.task_id` at the Space root.
|
| 25 |
+
# ---------------------------------------------------------------------------
|
| 26 |
+
TASKS = {
|
| 27 |
+
"dependency": {
|
| 28 |
+
"title": "Dependency Review",
|
| 29 |
+
"subtitle": "Supply-chain literacy",
|
| 30 |
+
"blurb": "Typosquats, hallucinated PyPI imports, pinned CVEs, license risks. Tests the baseline of supply-chain awareness every reviewer should have.",
|
| 31 |
+
"stats": "24 scenarios · 120 findings · Qwen 1.5B · 3 epochs",
|
| 32 |
+
"delta": "+0.302",
|
| 33 |
+
"deltatxt": "20 / 24 wins · 0.083 → 0.385",
|
| 34 |
+
"space_url": "https://huggingface.co/spaces/sam25kat/securereview-trainer",
|
| 35 |
+
},
|
| 36 |
+
"iac": {
|
| 37 |
+
"title": "IaC Misconfiguration",
|
| 38 |
+
"subtitle": "Cloud-security reasoning",
|
| 39 |
+
"blurb": "CIS violations in Terraform / K8s — public buckets, wildcard IAM, privileged containers, missing encryption. Multi-file cloud reasoning.",
|
| 40 |
+
"stats": "24 scenarios · 155 findings · Qwen 1.5B · 3 epochs",
|
| 41 |
+
"delta": "+0.126",
|
| 42 |
+
"deltatxt": "6 / 13 wins · 0.177 → 0.303",
|
| 43 |
+
"space_url": "https://huggingface.co/spaces/sam25kat/securereview-trainer-iac",
|
| 44 |
+
},
|
| 45 |
+
"migration": {
|
| 46 |
+
"title": "Migration Safety",
|
| 47 |
+
"subtitle": "Database engineering judgment",
|
| 48 |
+
"blurb": "SQL migrations against live production context — table sizes, write throughput, downstream services. Hot-row contention, RLS gaps, MVCC bloat.",
|
| 49 |
+
"stats": "12 curriculum-filtered (of 28) · 155 findings · Qwen 7B 4-bit · 3 epochs",
|
| 50 |
+
"delta": "+0.295",
|
| 51 |
+
"deltatxt": "10 / 12 wins · 0.170 → 0.465",
|
| 52 |
+
"space_url": "https://huggingface.co/spaces/sam25kat/securereview-trainer-migration",
|
| 53 |
+
},
|
| 54 |
+
}
|
| 55 |
+
TASK_ORDER = ["dependency", "iac", "migration"]
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def detect_local_task() -> str:
|
| 59 |
+
"""Each trainer Space puts its own task id in /.task_id — defaults to dep."""
|
| 60 |
+
if os.path.exists(TASK_ID_FILE):
|
| 61 |
+
try:
|
| 62 |
+
t = open(TASK_ID_FILE).read().strip()
|
| 63 |
+
if t in TASKS:
|
| 64 |
+
return t
|
| 65 |
+
except OSError:
|
| 66 |
+
pass
|
| 67 |
+
return "dependency"
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
LOCAL_TASK = detect_local_task()
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
# ---------------------------------------------------------------------------
|
| 74 |
|
| 75 |
def is_training_alive():
|
| 76 |
if not os.path.exists(PID_FILE):
|
|
|
|
| 104 |
pass
|
| 105 |
|
| 106 |
|
| 107 |
+
# ---------------------------------------------------------------------------
|
| 108 |
+
# Page chrome
|
| 109 |
+
# ---------------------------------------------------------------------------
|
| 110 |
+
|
| 111 |
st.set_page_config(page_title="SecureReview Trainer", layout="wide")
|
| 112 |
+
|
| 113 |
+
st.markdown(
|
| 114 |
+
"""
|
| 115 |
+
<style>
|
| 116 |
+
.hub-card {
|
| 117 |
+
border: 1px solid rgba(255,255,255,0.12);
|
| 118 |
+
border-radius: 10px;
|
| 119 |
+
padding: 22px 22px 18px 22px;
|
| 120 |
+
background: rgba(255,255,255,0.02);
|
| 121 |
+
height: 100%;
|
| 122 |
+
}
|
| 123 |
+
.hub-card.active {
|
| 124 |
+
border-color: #ff6b35;
|
| 125 |
+
background: rgba(255,107,53,0.06);
|
| 126 |
+
}
|
| 127 |
+
.hub-card h3 {
|
| 128 |
+
margin: 0 0 4px 0;
|
| 129 |
+
font-size: 17px;
|
| 130 |
+
}
|
| 131 |
+
.hub-card .sub {
|
| 132 |
+
color: #9ca3af;
|
| 133 |
+
font-size: 12px;
|
| 134 |
+
letter-spacing: 0.04em;
|
| 135 |
+
text-transform: uppercase;
|
| 136 |
+
margin-bottom: 14px;
|
| 137 |
+
}
|
| 138 |
+
.hub-card .blurb {
|
| 139 |
+
color: #d1d5db;
|
| 140 |
+
font-size: 13px;
|
| 141 |
+
line-height: 1.5;
|
| 142 |
+
min-height: 86px;
|
| 143 |
+
}
|
| 144 |
+
.hub-card .stats {
|
| 145 |
+
font-family: ui-monospace, Menlo, Monaco, "Courier New", monospace;
|
| 146 |
+
font-size: 11px;
|
| 147 |
+
color: #9ca3af;
|
| 148 |
+
margin-top: 12px;
|
| 149 |
+
padding-top: 12px;
|
| 150 |
+
border-top: 1px solid rgba(255,255,255,0.08);
|
| 151 |
+
}
|
| 152 |
+
.hub-card .delta {
|
| 153 |
+
font-size: 26px;
|
| 154 |
+
font-weight: 700;
|
| 155 |
+
color: #ff6b35;
|
| 156 |
+
margin-top: 8px;
|
| 157 |
+
letter-spacing: -0.02em;
|
| 158 |
+
}
|
| 159 |
+
.hub-card .delta-cap {
|
| 160 |
+
font-family: ui-monospace, Menlo, Monaco, "Courier New", monospace;
|
| 161 |
+
font-size: 11px;
|
| 162 |
+
color: #9ca3af;
|
| 163 |
+
}
|
| 164 |
+
.hub-card .badge {
|
| 165 |
+
display: inline-block;
|
| 166 |
+
font-family: ui-monospace, Menlo, Monaco, "Courier New", monospace;
|
| 167 |
+
font-size: 10px;
|
| 168 |
+
letter-spacing: 0.08em;
|
| 169 |
+
padding: 2px 8px;
|
| 170 |
+
border-radius: 4px;
|
| 171 |
+
background: #ff6b35;
|
| 172 |
+
color: #0a0a0a;
|
| 173 |
+
margin-left: 8px;
|
| 174 |
+
vertical-align: middle;
|
| 175 |
+
}
|
| 176 |
+
.hub-card a.openbtn {
|
| 177 |
+
display: inline-block;
|
| 178 |
+
margin-top: 16px;
|
| 179 |
+
padding: 8px 14px;
|
| 180 |
+
border: 1px solid rgba(255,255,255,0.2);
|
| 181 |
+
border-radius: 6px;
|
| 182 |
+
color: #d1d5db;
|
| 183 |
+
text-decoration: none;
|
| 184 |
+
font-size: 13px;
|
| 185 |
+
}
|
| 186 |
+
.hub-card a.openbtn:hover {
|
| 187 |
+
border-color: #ff6b35;
|
| 188 |
+
color: #ff6b35;
|
| 189 |
+
}
|
| 190 |
+
</style>
|
| 191 |
+
""",
|
| 192 |
+
unsafe_allow_html=True,
|
| 193 |
+
)
|
| 194 |
+
|
| 195 |
+
st.title("SecureReview — Trainer Hub")
|
| 196 |
+
st.markdown(
|
| 197 |
+
"**Three security-review domains. One canonical SFT → GRPO hybrid pipeline.** "
|
| 198 |
+
"Click *Run Training* on any card — full SFT run completes in ~30 s on a single GPU credit, "
|
| 199 |
+
"with loss curve + before/after plot rendered live."
|
| 200 |
+
)
|
| 201 |
+
st.markdown("---")
|
| 202 |
+
|
| 203 |
+
# ---------------------------------------------------------------------------
|
| 204 |
+
# Three task cards
|
| 205 |
+
# ---------------------------------------------------------------------------
|
| 206 |
+
|
| 207 |
+
cols = st.columns(3, gap="medium")
|
| 208 |
+
|
| 209 |
+
for idx, task_id in enumerate(TASK_ORDER):
|
| 210 |
+
cfg = TASKS[task_id]
|
| 211 |
+
is_active = task_id == LOCAL_TASK
|
| 212 |
+
with cols[idx]:
|
| 213 |
+
active_cls = "active" if is_active else ""
|
| 214 |
+
active_badge = '<span class="badge">THIS SPACE</span>' if is_active else ""
|
| 215 |
+
card_html = f"""
|
| 216 |
+
<div class="hub-card {active_cls}">
|
| 217 |
+
<h3>{cfg['title']}{active_badge}</h3>
|
| 218 |
+
<div class="sub">{cfg['subtitle']}</div>
|
| 219 |
+
<div class="blurb">{cfg['blurb']}</div>
|
| 220 |
+
<div class="delta">{cfg['delta']}</div>
|
| 221 |
+
<div class="delta-cap">{cfg['deltatxt']}</div>
|
| 222 |
+
<div class="stats">{cfg['stats']}</div>
|
| 223 |
+
"""
|
| 224 |
+
if not is_active:
|
| 225 |
+
card_html += f'<a class="openbtn" href="{cfg["space_url"]}" target="_blank">Open trainer ↗</a>'
|
| 226 |
+
card_html += "</div>"
|
| 227 |
+
st.markdown(card_html, unsafe_allow_html=True)
|
| 228 |
+
|
| 229 |
+
st.markdown("")
|
| 230 |
+
st.markdown("---")
|
| 231 |
+
|
| 232 |
+
# ---------------------------------------------------------------------------
|
| 233 |
+
# Active-task training panel
|
| 234 |
+
# ---------------------------------------------------------------------------
|
| 235 |
+
|
| 236 |
+
active_cfg = TASKS[LOCAL_TASK]
|
| 237 |
+
st.subheader(f"▶ {active_cfg['title']} · run training here")
|
| 238 |
st.markdown(
|
| 239 |
+
f"Trains via SFT → GRPO on the live `{LOCAL_TASK}_review` task of the "
|
| 240 |
+
f"SecureReview environment. Reward comes from the live grader — no static dataset."
|
| 241 |
)
|
| 242 |
|
| 243 |
done = os.path.exists(DONE_FILE)
|
| 244 |
log_present = os.path.exists(LOG_FILE)
|
| 245 |
training_alive = is_training_alive()
|
| 246 |
+
ongoing = log_present and not done
|
|
|
|
|
|
|
| 247 |
|
| 248 |
if not ongoing and not done:
|
| 249 |
if st.button("▶ Run Training", type="primary"):
|