andandandand commited on
Commit
e26e421
·
verified ·
1 Parent(s): 961ebda

Fix bind host fallback for HF runtime

Browse files
Files changed (1) hide show
  1. demo.py +35 -3
demo.py CHANGED
@@ -16,7 +16,7 @@ import hyperview as hv
16
  from hyperview.core.sample import Sample
17
 
18
  SPACE_HOST = os.environ.get("SPACE_HOST", "0.0.0.0")
19
- SPACE_PORT = int(os.environ.get("SPACE_PORT", "7860"))
20
 
21
  DATASET_NAME = os.environ.get("HYPERVIEW_DATASET_NAME", "jaguar_core_claims_demo")
22
  HF_DATASET_REPO = os.environ.get("HF_DATASET_REPO", "hyper3labs/jaguar-hyperview-demo")
@@ -34,6 +34,28 @@ ASSET_MANIFEST_PATH = Path(
34
  )
35
 
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  def load_asset_manifest(path: Path) -> dict[str, Any]:
38
  if not path.exists():
39
  raise FileNotFoundError(
@@ -199,8 +221,18 @@ def main() -> None:
199
  print("Preparation-only mode enabled; skipping server launch.")
200
  return
201
 
202
- print(f"Starting HyperView on {SPACE_HOST}:{SPACE_PORT}")
203
- hv.launch(dataset, host=SPACE_HOST, port=SPACE_PORT, open_browser=False)
 
 
 
 
 
 
 
 
 
 
204
 
205
 
206
  if __name__ == "__main__":
 
16
  from hyperview.core.sample import Sample
17
 
18
  SPACE_HOST = os.environ.get("SPACE_HOST", "0.0.0.0")
19
+ LOCAL_BIND_HOSTS = {"0.0.0.0", "127.0.0.1", "localhost", "::", "::1"}
20
 
21
  DATASET_NAME = os.environ.get("HYPERVIEW_DATASET_NAME", "jaguar_core_claims_demo")
22
  HF_DATASET_REPO = os.environ.get("HF_DATASET_REPO", "hyper3labs/jaguar-hyperview-demo")
 
34
  )
35
 
36
 
37
+ def _resolve_bind_host() -> tuple[str, str | None]:
38
+ explicit_bind = os.environ.get("HYPERVIEW_BIND_HOST")
39
+ if explicit_bind:
40
+ return explicit_bind, None
41
+
42
+ if SPACE_HOST in LOCAL_BIND_HOSTS:
43
+ return SPACE_HOST, None
44
+
45
+ return "0.0.0.0", f"SPACE_HOST='{SPACE_HOST}' is non-local; falling back to 0.0.0.0"
46
+
47
+
48
+ def _resolve_port() -> int:
49
+ for key in ("SPACE_PORT", "PORT"):
50
+ value = os.environ.get(key)
51
+ if value:
52
+ try:
53
+ return int(value)
54
+ except ValueError as exc:
55
+ raise ValueError(f"Invalid integer value for {key}: {value}") from exc
56
+ return 7860
57
+
58
+
59
  def load_asset_manifest(path: Path) -> dict[str, Any]:
60
  if not path.exists():
61
  raise FileNotFoundError(
 
221
  print("Preparation-only mode enabled; skipping server launch.")
222
  return
223
 
224
+ bind_host, bind_warning = _resolve_bind_host()
225
+ bind_port = _resolve_port()
226
+
227
+ if bind_warning:
228
+ print(f"Bind host notice: {bind_warning}")
229
+ print(
230
+ "Starting HyperView with "
231
+ f"bind_host={bind_host} bind_port={bind_port} "
232
+ f"(SPACE_HOST={SPACE_HOST!r}, SPACE_PORT={os.environ.get('SPACE_PORT')!r}, "
233
+ f"PORT={os.environ.get('PORT')!r})"
234
+ )
235
+ hv.launch(dataset, host=bind_host, port=bind_port, open_browser=False)
236
 
237
 
238
  if __name__ == "__main__":