#!/usr/bin/env python """Hugging Face Spaces entrypoint for HyperView. This script serves a pre-computed demo dataset stored in LanceDB. The dataset is computed at Docker build time by scripts/precompute_hf_demo.py. For HuggingFace Spaces deployment under Hyper3Labs/HyperView. """ import os # Configuration from environment HOST = os.environ.get("HOST", "0.0.0.0") PORT = int(os.environ.get("PORT", 7860)) DATASET_NAME = os.environ.get("DEMO_DATASET", "cifar10_hf_demo") def main() -> None: """Load pre-computed dataset and launch server.""" import hyperview as hv dataset = hv.Dataset(DATASET_NAME) spaces = dataset.list_spaces() layouts = dataset.list_layouts() if not spaces or not layouts: print("Pre-computed embeddings not found in storage.") print("Falling back to computing on startup (this will be slow)...") from scripts.precompute_hf_demo import create_demo_dataset dataset = create_demo_dataset() else: print(f"Loaded dataset '{DATASET_NAME}' with pre-computed embeddings") print(f"\nStarting HyperView server on {HOST}:{PORT}") print("=" * 50) hv.launch( dataset, host=HOST, port=PORT, open_browser=False, ) if __name__ == "__main__": main()