mcthebest commited on
Commit
4bb26b1
Β·
verified Β·
1 Parent(s): e1e7af0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -17
app.py CHANGED
@@ -17,16 +17,11 @@ st.set_page_config(
17
  # ── Custom CSS ───────────────────────────────────────────────────────
18
  st.markdown("""
19
  <style>
20
- /* Main background */
21
  .stApp { background-color: #0d1117; color: #e6edf3; }
22
-
23
- /* Sidebar */
24
  [data-testid="stSidebar"] {
25
  background-color: #161b22;
26
  border-right: 1px solid #30363d;
27
  }
28
-
29
- /* Cards */
30
  .metric-card {
31
  background: #161b22;
32
  border: 1px solid #30363d;
@@ -36,8 +31,6 @@ st.markdown("""
36
  }
37
  .metric-card h3 { margin: 0; font-size: 13px; color: #8b949e; text-transform: uppercase; letter-spacing: 0.05em; }
38
  .metric-card p { margin: 4px 0 0; font-size: 28px; font-weight: 700; color: #58a6ff; }
39
-
40
- /* Detection table */
41
  .det-row {
42
  display: flex; align-items: center; gap: 10px;
43
  padding: 8px 12px; border-radius: 6px;
@@ -54,15 +47,11 @@ st.markdown("""
54
  flex: 1; height: 6px; background: #21262d; border-radius: 3px; overflow: hidden;
55
  }
56
  .score-bar-fill { height: 100%; border-radius: 3px; }
57
-
58
- /* Upload zone */
59
  [data-testid="stFileUploader"] > div:first-child {
60
  border: 2px dashed #30363d !important;
61
  border-radius: 10px !important;
62
  background: #161b22 !important;
63
  }
64
-
65
- /* Buttons */
66
  .stButton > button {
67
  width: 100%;
68
  background: #238636 !important;
@@ -74,10 +63,7 @@ st.markdown("""
74
  transition: background 0.2s;
75
  }
76
  .stButton > button:hover { background: #2ea043 !important; }
77
-
78
- /* Slider */
79
  .stSlider > div > div > div > div { background: #238636 !important; }
80
-
81
  h1, h2, h3 { color: #e6edf3 !important; }
82
  hr { border-color: #21262d; }
83
  </style>
@@ -107,15 +93,20 @@ COLORS_HEX = [
107
  # ── Model loader (cached) ────────────────────────────────────────────
108
  @st.cache_resource(show_spinner="Loading RT-DETRv4 model…")
109
  def get_model():
110
- """Load model once and cache across reruns."""
111
  ROOT = Path(__file__).resolve().parent
112
  sys.path.insert(0, str(ROOT))
113
 
114
  from engine.core import YAMLConfig
 
115
  import torch
116
  import torch.nn as nn
117
 
118
- CHECKPOINT = ROOT / "outputs" / "rtv4_hgnetv2_x_pcb" / "last.pth"
 
 
 
 
 
119
  CONFIG = ROOT / "configs" / "rtv4" / "rtv4_hgnetv2_x_pcb.yml"
120
  NUM_CLASSES = 9
121
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
@@ -315,4 +306,4 @@ st.download_button(
315
  file_name=f"{Path(uploaded.name).stem}_detected.png",
316
  mime="image/png",
317
  use_container_width=True,
318
- )
 
17
  # ── Custom CSS ───────────────────────────────────────────────────────
18
  st.markdown("""
19
  <style>
 
20
  .stApp { background-color: #0d1117; color: #e6edf3; }
 
 
21
  [data-testid="stSidebar"] {
22
  background-color: #161b22;
23
  border-right: 1px solid #30363d;
24
  }
 
 
25
  .metric-card {
26
  background: #161b22;
27
  border: 1px solid #30363d;
 
31
  }
32
  .metric-card h3 { margin: 0; font-size: 13px; color: #8b949e; text-transform: uppercase; letter-spacing: 0.05em; }
33
  .metric-card p { margin: 4px 0 0; font-size: 28px; font-weight: 700; color: #58a6ff; }
 
 
34
  .det-row {
35
  display: flex; align-items: center; gap: 10px;
36
  padding: 8px 12px; border-radius: 6px;
 
47
  flex: 1; height: 6px; background: #21262d; border-radius: 3px; overflow: hidden;
48
  }
49
  .score-bar-fill { height: 100%; border-radius: 3px; }
 
 
50
  [data-testid="stFileUploader"] > div:first-child {
51
  border: 2px dashed #30363d !important;
52
  border-radius: 10px !important;
53
  background: #161b22 !important;
54
  }
 
 
55
  .stButton > button {
56
  width: 100%;
57
  background: #238636 !important;
 
63
  transition: background 0.2s;
64
  }
65
  .stButton > button:hover { background: #2ea043 !important; }
 
 
66
  .stSlider > div > div > div > div { background: #238636 !important; }
 
67
  h1, h2, h3 { color: #e6edf3 !important; }
68
  hr { border-color: #21262d; }
69
  </style>
 
93
  # ── Model loader (cached) ────────────────────────────────────────────
94
  @st.cache_resource(show_spinner="Loading RT-DETRv4 model…")
95
  def get_model():
 
96
  ROOT = Path(__file__).resolve().parent
97
  sys.path.insert(0, str(ROOT))
98
 
99
  from engine.core import YAMLConfig
100
+ from huggingface_hub import hf_hub_download # ← added
101
  import torch
102
  import torch.nn as nn
103
 
104
+ # ← changed: download from model repo instead of local path
105
+ CHECKPOINT = Path(hf_hub_download(
106
+ repo_id="mcthebest/PCB_RTDETR",
107
+ repo_type="model",
108
+ filename="last.pth",
109
+ ))
110
  CONFIG = ROOT / "configs" / "rtv4" / "rtv4_hgnetv2_x_pcb.yml"
111
  NUM_CLASSES = 9
112
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
 
306
  file_name=f"{Path(uploaded.name).stem}_detected.png",
307
  mime="image/png",
308
  use_container_width=True,
309
+ )