perf: preload all checkpoints at boot so routing never pays a model load
Browse files
app.py
CHANGED
|
@@ -52,6 +52,12 @@ try:
|
|
| 52 |
except Exception as e:
|
| 53 |
print("warmup skipped:", type(e).__name__, e, flush=True)
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
MODEL_REPO = D.MODEL_REPO
|
| 56 |
ANSWER_COLS = ["question", "answer", "confidence"]
|
| 57 |
|
|
@@ -116,7 +122,7 @@ def run_playground(state_text, questions_text):
|
|
| 116 |
def run_routing(text):
|
| 117 |
"""Routing tab. Wrapped so a failure shows in the tab instead of breaking the app."""
|
| 118 |
if not ROUTING_OK:
|
| 119 |
-
return [], "**Routing unavailable** — this Space needs `laya>=0.
|
| 120 |
try:
|
| 121 |
return gpu_call(R.analyse_and_answer, text)
|
| 122 |
except Exception as e:
|
|
@@ -238,7 +244,7 @@ with gr.Blocks(title="Laya", theme=gr.themes.Soft()) as demo:
|
|
| 238 |
"Khmer scores **0.000 accuracy at 0.952 confidence** on the English checkpoint."
|
| 239 |
)
|
| 240 |
if not ROUTING_OK:
|
| 241 |
-
gr.Markdown("> **Unavailable** — this Space needs `laya>=0.
|
| 242 |
with gr.Row():
|
| 243 |
with gr.Column():
|
| 244 |
ml_in = gr.Textbox(
|
|
|
|
| 52 |
except Exception as e:
|
| 53 |
print("warmup skipped:", type(e).__name__, e, flush=True)
|
| 54 |
|
| 55 |
+
if ROUTING_OK: # build and warm every routed checkpoint before the UI opens
|
| 56 |
+
try:
|
| 57 |
+
print(R.warmup(), flush=True)
|
| 58 |
+
except Exception as e:
|
| 59 |
+
print("routing warmup skipped:", type(e).__name__, e, flush=True)
|
| 60 |
+
|
| 61 |
MODEL_REPO = D.MODEL_REPO
|
| 62 |
ANSWER_COLS = ["question", "answer", "confidence"]
|
| 63 |
|
|
|
|
| 122 |
def run_routing(text):
|
| 123 |
"""Routing tab. Wrapped so a failure shows in the tab instead of breaking the app."""
|
| 124 |
if not ROUTING_OK:
|
| 125 |
+
return [], "**Routing unavailable** — this Space needs `laya>=0.3.0`.", "{}"
|
| 126 |
try:
|
| 127 |
return gpu_call(R.analyse_and_answer, text)
|
| 128 |
except Exception as e:
|
|
|
|
| 244 |
"Khmer scores **0.000 accuracy at 0.952 confidence** on the English checkpoint."
|
| 245 |
)
|
| 246 |
if not ROUTING_OK:
|
| 247 |
+
gr.Markdown("> **Unavailable** — this Space needs `laya>=0.3.0`. The other tabs are unaffected.")
|
| 248 |
with gr.Row():
|
| 249 |
with gr.Column():
|
| 250 |
ml_in = gr.Textbox(
|