Spaces:
Sleeping
Sleeping
Pointf5ive commited on
Commit 路
08ae10d
1
Parent(s): 78d0b70
Show live TOTEM API run stamp
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import html
|
|
| 5 |
import json
|
| 6 |
import os
|
| 7 |
import re
|
|
|
|
| 8 |
import datetime
|
| 9 |
from shutil import copy2
|
| 10 |
from html import escape
|
|
@@ -47,6 +48,22 @@ WORKBOOK_HOME_DIR = Path("data/workbook_home")
|
|
| 47 |
ACTIVE_WORKBOOK_PATH = WORKBOOK_HOME_DIR / "active_workbook.xlsx"
|
| 48 |
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
def _patch_gradio_schema_bool_compat() -> None:
|
| 51 |
"""
|
| 52 |
Compatibility shim for Gradio API schema parsing where boolean JSON schema
|
|
@@ -3160,6 +3177,19 @@ def _bridge_verification_notes(debug: dict, llm_state: dict) -> dict:
|
|
| 3160 |
}
|
| 3161 |
|
| 3162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3163 |
def analyze_manuscript_and_refresh(
|
| 3164 |
file_obj,
|
| 3165 |
author_name: str,
|
|
@@ -3251,6 +3281,7 @@ def run_totem_analysis_from_context(active_path: str, manuscript_context_json: s
|
|
| 3251 |
path = _validate_workbook_path(Path(active_path) if active_path else _preferred_workbook_path())
|
| 3252 |
rubric = extract_workbook_matrix(path)
|
| 3253 |
llm_state, debug = run_totem_skill(rubric_matrix=rubric, manuscript=ctx)
|
|
|
|
| 3254 |
dashboard_html, log_df, summary, gate_summary = _apply_llm_dashboard_state(
|
| 3255 |
active_path=active_path,
|
| 3256 |
llm_state=llm_state,
|
|
@@ -3339,14 +3370,14 @@ with gr.Blocks(title="TOTEM Studio") as demo:
|
|
| 3339 |
with gr.TabItem("Dashboard"):
|
| 3340 |
dashboard = gr.HTML(value=initial_dashboard_html())
|
| 3341 |
gr.HTML(
|
| 3342 |
-
"<div style='max-width:1180px;margin:10px auto 12px auto;padding:10px 14px;"
|
| 3343 |
-
"border:1px solid rgba(242,193,78,.35);border-radius:10px;"
|
| 3344 |
-
"background:rgba(10,22,45,.85);color:#f6f1e8;font-size:13px;'>"
|
| 3345 |
-
"<b>Mode:</b> Draft Mode (ORDER_91) keeps manuscript extraction separate from scoring. "
|
| 3346 |
-
"Only <b>Run TOTEM Analysis</b> updates the 6 scoring metrics. "
|
| 3347 |
-
"<span style='opacity:.95;color:#8df0b5;font-weight:700'>BRIDGE ACTIVE</span> 路 "
|
| 3348 |
-
"<span style='opacity:.8'>Build:
|
| 3349 |
-
"</div>"
|
| 3350 |
)
|
| 3351 |
|
| 3352 |
with gr.Row(elem_id="studio-actions"):
|
|
|
|
| 5 |
import json
|
| 6 |
import os
|
| 7 |
import re
|
| 8 |
+
import subprocess
|
| 9 |
import datetime
|
| 10 |
from shutil import copy2
|
| 11 |
from html import escape
|
|
|
|
| 48 |
ACTIVE_WORKBOOK_PATH = WORKBOOK_HOME_DIR / "active_workbook.xlsx"
|
| 49 |
|
| 50 |
|
| 51 |
+
def app_build_label() -> str:
|
| 52 |
+
for env_name in ("SPACE_COMMIT_SHA", "COMMIT_SHA", "GIT_COMMIT"):
|
| 53 |
+
value = os.getenv(env_name)
|
| 54 |
+
if value:
|
| 55 |
+
return value[:7]
|
| 56 |
+
try:
|
| 57 |
+
return subprocess.check_output(
|
| 58 |
+
["git", "rev-parse", "--short", "HEAD"],
|
| 59 |
+
cwd=Path(__file__).resolve().parent,
|
| 60 |
+
text=True,
|
| 61 |
+
stderr=subprocess.DEVNULL,
|
| 62 |
+
).strip()
|
| 63 |
+
except Exception:
|
| 64 |
+
return "unknown"
|
| 65 |
+
|
| 66 |
+
|
| 67 |
def _patch_gradio_schema_bool_compat() -> None:
|
| 68 |
"""
|
| 69 |
Compatibility shim for Gradio API schema parsing where boolean JSON schema
|
|
|
|
| 3177 |
}
|
| 3178 |
|
| 3179 |
|
| 3180 |
+
def _annotate_dashboard_message_with_run(llm_state: dict, debug: dict) -> None:
|
| 3181 |
+
tx = str(debug.get("token_audit_transaction_id") or "").strip()
|
| 3182 |
+
provider = str(debug.get("provider") or "api").strip()
|
| 3183 |
+
model = str(debug.get("model") or "").strip()
|
| 3184 |
+
actual = debug.get("actual_tokens") if isinstance(debug.get("actual_tokens"), dict) else {}
|
| 3185 |
+
total_tokens = actual.get("total_tokens")
|
| 3186 |
+
short_tx = tx[-10:] if tx else "no-tx"
|
| 3187 |
+
model_label = model.split("/")[-1] if model else "model"
|
| 3188 |
+
usage_label = f"{total_tokens} tokens" if total_tokens not in (None, "", 0) else "usage pending"
|
| 3189 |
+
base = str(llm_state.get("dashboard_message") or "TOTEM analysis complete.").strip()
|
| 3190 |
+
llm_state["dashboard_message"] = f"{base} 路 API {provider}/{model_label} 路 run {short_tx} 路 {usage_label}"
|
| 3191 |
+
|
| 3192 |
+
|
| 3193 |
def analyze_manuscript_and_refresh(
|
| 3194 |
file_obj,
|
| 3195 |
author_name: str,
|
|
|
|
| 3281 |
path = _validate_workbook_path(Path(active_path) if active_path else _preferred_workbook_path())
|
| 3282 |
rubric = extract_workbook_matrix(path)
|
| 3283 |
llm_state, debug = run_totem_skill(rubric_matrix=rubric, manuscript=ctx)
|
| 3284 |
+
_annotate_dashboard_message_with_run(llm_state, debug)
|
| 3285 |
dashboard_html, log_df, summary, gate_summary = _apply_llm_dashboard_state(
|
| 3286 |
active_path=active_path,
|
| 3287 |
llm_state=llm_state,
|
|
|
|
| 3370 |
with gr.TabItem("Dashboard"):
|
| 3371 |
dashboard = gr.HTML(value=initial_dashboard_html())
|
| 3372 |
gr.HTML(
|
| 3373 |
+
f"<div style='max-width:1180px;margin:10px auto 12px auto;padding:10px 14px;"
|
| 3374 |
+
f"border:1px solid rgba(242,193,78,.35);border-radius:10px;"
|
| 3375 |
+
f"background:rgba(10,22,45,.85);color:#f6f1e8;font-size:13px;'>"
|
| 3376 |
+
f"<b>Mode:</b> Draft Mode (ORDER_91) keeps manuscript extraction separate from scoring. "
|
| 3377 |
+
f"Only <b>Run TOTEM Analysis</b> updates the 6 scoring metrics. "
|
| 3378 |
+
f"<span style='opacity:.95;color:#8df0b5;font-weight:700'>BRIDGE ACTIVE</span> 路 "
|
| 3379 |
+
f"<span style='opacity:.8'>Build: {app_build_label()}</span>"
|
| 3380 |
+
f"</div>"
|
| 3381 |
)
|
| 3382 |
|
| 3383 |
with gr.Row(elem_id="studio-actions"):
|