mahmoud611 commited on
Commit
bbcbd17
·
verified ·
1 Parent(s): a82aa47

Upload api.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. api.py +18 -9
api.py CHANGED
@@ -40,12 +40,13 @@ def _ensure_weights():
40
  continue
41
  try:
42
  from huggingface_hub import hf_hub_download
43
- print(f" Downloading {fname} from HF...", flush=True)
 
44
  dest = hf_hub_download(
45
- repo_id="mahmoud611/cardioscreen-api",
46
- filename=f"weights/{fname}",
47
- repo_type="space",
48
- local_dir=os.path.dirname(os.path.abspath(__file__)),
49
  )
50
  # Ensure it landed in the right place
51
  if dest != fpath and os.path.exists(dest):
@@ -100,13 +101,21 @@ app.add_middleware(
100
  async def health_check():
101
  """Health check — confirms the API is running."""
102
  import inference
 
 
 
 
103
  return {
104
  "status": "ok",
105
  "service": "CardioScreen AI",
106
- "version": "2.0",
107
- "cnn_available": inference._cnn_available,
108
- "weights_pt_exists": os.path.exists(WEIGHTS_PT),
109
- "weights_pt_size": os.path.getsize(WEIGHTS_PT) if os.path.exists(WEIGHTS_PT) else 0,
 
 
 
 
110
  "startup_errors": _startup_errors,
111
  }
112
 
 
40
  continue
41
  try:
42
  from huggingface_hub import hf_hub_download
43
+ print(f" Downloading {fname} from HF model repo...", flush=True)
44
+ # Download from public model repo (not Space — Space requires auth)
45
  dest = hf_hub_download(
46
+ repo_id="mahmoud611/cardioscreen-weights",
47
+ filename=fname,
48
+ repo_type="model",
49
+ local_dir=WEIGHTS_DIR,
50
  )
51
  # Ensure it landed in the right place
52
  if dest != fpath and os.path.exists(dest):
 
101
  async def health_check():
102
  """Health check — confirms the API is running."""
103
  import inference
104
+ weights_status = {
105
+ f: os.path.exists(os.path.join(WEIGHTS_DIR, f))
106
+ for f in WEIGHT_FILES if f.endswith(".pt")
107
+ }
108
  return {
109
  "status": "ok",
110
  "service": "CardioScreen AI",
111
+ "version": "3.0",
112
+ "models": {
113
+ "joint_cnn": inference._cnn_available,
114
+ "finetuned_cnn": inference._finetuned_available,
115
+ "resnet18": inference._resnet_available,
116
+ "bigru": inference._gru_available,
117
+ },
118
+ "weights": weights_status,
119
  "startup_errors": _startup_errors,
120
  }
121