stevafernandes commited on
Commit
98f01d3
·
verified ·
1 Parent(s): 812b6ee

Deploy CellQuant

Browse files
Files changed (2) hide show
  1. .gitattributes +7 -0
  2. scripts/deploy_hf.py +14 -4
.gitattributes CHANGED
@@ -1 +1,8 @@
1
  *.pt filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
1
  *.pt filter=lfs diff=lfs merge=lfs -text
2
+ # The Hub stores binary files (images included) as LFS objects; without a filter line the
3
+ # Space checkout keeps the 131-byte pointer and the app cannot read the example image.
4
+ *.png filter=lfs diff=lfs merge=lfs -text
5
+ *.jpg filter=lfs diff=lfs merge=lfs -text
6
+ *.jpeg filter=lfs diff=lfs merge=lfs -text
7
+ *.tif filter=lfs diff=lfs merge=lfs -text
8
+ *.tiff filter=lfs diff=lfs merge=lfs -text
scripts/deploy_hf.py CHANGED
@@ -5,7 +5,9 @@
5
 
6
  Uses the token from `hf auth login` (or HF_TOKEN). Large files (the .pt checkpoint)
7
  are uploaded through LFS automatically. Then polls the Space runtime and, once it is
8
- RUNNING, calls its API with the bundled example image to prove it works.
 
 
9
  """
10
  from __future__ import annotations
11
 
@@ -60,12 +62,20 @@ def main(argv=None):
60
  time.sleep(15)
61
  else:
62
  raise SystemExit("timed out waiting for the Space")
63
- # smoke test through the Gradio API
 
 
 
 
 
 
 
 
 
64
  from gradio_client import Client, handle_file
65
  client = Client(repo, hf_token=get_token())
66
- ex = os.path.join(ROOT, "examples", "F100_crop_512.png")
67
  t = time.time()
68
- out = client.predict([handle_file(ex)], "none (fastest)", 0.5, 0.5, 50, "head", "contains", False, api_name="/analyze_files")
69
  print(f"API call ok in {time.time()-t:.1f}s; counts row: {out[0]['data'][0] if isinstance(out[0], dict) else out[0]}")
70
 
71
 
 
5
 
6
  Uses the token from `hf auth login` (or HF_TOKEN). Large files (the .pt checkpoint)
7
  are uploaded through LFS automatically. Then polls the Space runtime and, once it is
8
+ RUNNING, checks that the Space serves the bundled example image as a real PNG (the Hub
9
+ stores binary files as LFS objects, and a checkout only resolves them for extensions
10
+ listed in .gitattributes) and calls the API with it to prove the model works.
11
  """
12
  from __future__ import annotations
13
 
 
62
  time.sleep(15)
63
  else:
64
  raise SystemExit("timed out waiting for the Space")
65
+ # the example image as the Space itself serves it must be a PNG, not an LFS pointer
66
+ import requests
67
+ host = api.space_info(repo).host or f"https://{repo.replace('/', '-')}.hf.space"
68
+ served = f"{host.rstrip('/')}/gradio_api/file=/home/user/app/examples/F100_crop_512.png"
69
+ r = requests.get(served, timeout=60)
70
+ if r.status_code != 200 or not r.content.startswith(b"\x89PNG"):
71
+ raise SystemExit(f"Space serves {served} as {r.status_code} / {len(r.content)} bytes starting {r.content[:40]!r}: "
72
+ "not a PNG (unresolved LFS pointer? check .gitattributes)")
73
+ print(f"served example ok: {len(r.content)} bytes")
74
+ # smoke test through the Gradio API with that served copy
75
  from gradio_client import Client, handle_file
76
  client = Client(repo, hf_token=get_token())
 
77
  t = time.time()
78
+ out = client.predict([handle_file(served)], "none (fastest)", 0.5, 0.5, 50, "head", "contains", False, api_name="/analyze_files")
79
  print(f"API call ok in {time.time()-t:.1f}s; counts row: {out[0]['data'][0] if isinstance(out[0], dict) else out[0]}")
80
 
81