Pranav commited on
Commit
45aedbf
·
1 Parent(s): f54e27b

fix: remove blocking warmup to pass HF health check

Browse files
Files changed (1) hide show
  1. streamlit/app.py +2 -52
streamlit/app.py CHANGED
@@ -1,4 +1,4 @@
1
- import sys, os, time
2
  sys.path.append(os.path.dirname(os.path.dirname(__file__))) # import inference/
3
 
4
  import streamlit as st
@@ -9,68 +9,18 @@ log = get_logger("app")
9
 
10
  st.set_page_config(page_title="Yugensys Vision AI — Manufacturing", layout="wide")
11
 
12
- # ---------------------------------------------------------------------------
13
- # Imports — deferred so the page renders before any heavy loading starts
14
- # ---------------------------------------------------------------------------
15
  from inference.detect import detect_assets, _model as get_poc1_model
16
  from inference.classify import classify_qc, get_efficientnet, get_yolo
17
 
18
  # ---------------------------------------------------------------------------
19
- # Model warm-up — runs AFTER the first render so HF health check passes
20
- # ---------------------------------------------------------------------------
21
- STEPS = [
22
- (get_poc1_model, "Loading POC1 · Asset Detection model…", 0.00, 0.34),
23
- (get_efficientnet, "Loading POC2 · EfficientNet classifier…", 0.34, 0.67),
24
- (get_yolo, "Loading POC2 · YOLOv11 fallback…", 0.67, 1.00),
25
- ]
26
-
27
- def models_ready() -> bool:
28
- """True once all three @st.cache_resource loaders have been called."""
29
- return st.session_state.get("models_loaded", False)
30
-
31
- def run_warmup():
32
- """Blocking warm-up with progress bar — only called when models aren't cached yet."""
33
- log.info("=== warm-up started ===")
34
- t_total = time.perf_counter()
35
-
36
- container = st.empty()
37
- with container.container():
38
- st.markdown("### ⚙️ Starting Yugensys Vision AI…")
39
- bar = st.progress(0.0)
40
- label = st.empty()
41
-
42
- for loader, msg, start_pct, end_pct in STEPS:
43
- label.caption(msg)
44
- bar.progress(start_pct)
45
- t0 = time.perf_counter()
46
- loader()
47
- elapsed = time.perf_counter() - t0
48
- log.info("warm-up step done: %s (%.2fs)", msg, elapsed)
49
- bar.progress(end_pct)
50
-
51
- label.caption("✅ All models loaded — ready!")
52
- time.sleep(0.5)
53
-
54
- container.empty()
55
- st.session_state["models_loaded"] = True
56
- log.info("=== warm-up complete total=%.2fs ===", time.perf_counter() - t_total)
57
-
58
- # ---------------------------------------------------------------------------
59
- # Sidebar + main UI — rendered on EVERY run (including the very first one)
60
- # so HF health check gets a valid HTTP response immediately
61
  # ---------------------------------------------------------------------------
62
  st.sidebar.title("Yugensys Vision AI")
63
  screen = st.sidebar.radio(
64
  "Select POC",
65
  ["Asset Identification", "Quality Inspection (Auto Fallback)"],
66
- disabled=not models_ready(), # grey out nav until models are ready
67
  )
68
 
69
- # Now do the blocking warm-up (only on cache miss — fast no-op afterwards)
70
- if not models_ready():
71
- run_warmup()
72
- st.rerun() # re-render with nav enabled and warm-up UI gone
73
-
74
  # ---------------------------------------------------------------------------
75
  # POC screens
76
  # ---------------------------------------------------------------------------
 
1
+ import sys, os, time # time kept for perf logging in inference calls
2
  sys.path.append(os.path.dirname(os.path.dirname(__file__))) # import inference/
3
 
4
  import streamlit as st
 
9
 
10
  st.set_page_config(page_title="Yugensys Vision AI — Manufacturing", layout="wide")
11
 
 
 
 
12
  from inference.detect import detect_assets, _model as get_poc1_model
13
  from inference.classify import classify_qc, get_efficientnet, get_yolo
14
 
15
  # ---------------------------------------------------------------------------
16
+ # Sidebar + main UI — models load lazily on-demand via @st.cache_resource
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  # ---------------------------------------------------------------------------
18
  st.sidebar.title("Yugensys Vision AI")
19
  screen = st.sidebar.radio(
20
  "Select POC",
21
  ["Asset Identification", "Quality Inspection (Auto Fallback)"],
 
22
  )
23
 
 
 
 
 
 
24
  # ---------------------------------------------------------------------------
25
  # POC screens
26
  # ---------------------------------------------------------------------------