Spaces:
Sleeping
Sleeping
preload backbone at startup + timing/multi-photo hint in description
Browse files
app.py
CHANGED
|
@@ -30,9 +30,21 @@ def get_session() -> InferenceSession:
|
|
| 30 |
global _SESS
|
| 31 |
if _SESS is None:
|
| 32 |
_SESS = InferenceSession.from_hub(repo_id="bubbaonbubba/pockethb-base")
|
|
|
|
|
|
|
|
|
|
| 33 |
return _SESS
|
| 34 |
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
def _make_chart(raw_per: np.ndarray, personal_per: np.ndarray | None, true_hb: float | None) -> Image.Image:
|
| 37 |
fig, ax = plt.subplots(figsize=(9, 4.5))
|
| 38 |
idx = np.arange(len(raw_per))
|
|
@@ -135,6 +147,8 @@ see the per-user calibrator fit on the spot.
|
|
| 135 |
[capture protocol](https://github.com/jayanthvee/pocketHb/blob/main/docs/capture_protocol.md)
|
| 136 |
|
| 137 |
**not a medical device. research replication only. do not use to estimate anyone's actual hemoglobin in any clinical, diagnostic, or treatment context. not FDA cleared. get a blood test.**
|
|
|
|
|
|
|
| 138 |
"""
|
| 139 |
|
| 140 |
with gr.Blocks(title="pocketHb demo") as demo:
|
|
|
|
| 30 |
global _SESS
|
| 31 |
if _SESS is None:
|
| 32 |
_SESS = InferenceSession.from_hub(repo_id="bubbaonbubba/pockethb-base")
|
| 33 |
+
# Warm the frozen backbone so the first user-facing request doesn't
|
| 34 |
+
# eat the ~30-60s cold-start cost on cpu-basic.
|
| 35 |
+
_SESS._get_backbone()
|
| 36 |
return _SESS
|
| 37 |
|
| 38 |
|
| 39 |
+
# preload at module-import time so HF Spaces boot absorbs the cold start,
|
| 40 |
+
# not the first user request
|
| 41 |
+
try:
|
| 42 |
+
get_session()
|
| 43 |
+
print("[startup] InferenceSession warm — backbone loaded.")
|
| 44 |
+
except Exception as e:
|
| 45 |
+
print(f"[startup] warm-up failed (will retry on first request): {type(e).__name__}: {e}")
|
| 46 |
+
|
| 47 |
+
|
| 48 |
def _make_chart(raw_per: np.ndarray, personal_per: np.ndarray | None, true_hb: float | None) -> Image.Image:
|
| 49 |
fig, ax = plt.subplots(figsize=(9, 4.5))
|
| 50 |
idx = np.arange(len(raw_per))
|
|
|
|
| 147 |
[capture protocol](https://github.com/jayanthvee/pocketHb/blob/main/docs/capture_protocol.md)
|
| 148 |
|
| 149 |
**not a medical device. research replication only. do not use to estimate anyone's actual hemoglobin in any clinical, diagnostic, or treatment context. not FDA cleared. get a blood test.**
|
| 150 |
+
|
| 151 |
+
_runs on a free cpu-basic Space; expect ~5 s per photo. uploading 3+ photos at once is recommended — the model was trained on 3-crop bags per patient and single-photo inference is off-distribution._
|
| 152 |
"""
|
| 153 |
|
| 154 |
with gr.Blocks(title="pocketHb demo") as demo:
|