Spaces:
Sleeping
Sleeping
Download app.py from farrell236/OCT_Segmentation_a2: direct link, hf CLI and curl.
- Browser
- Download file 2.28 kB
-
https://huggingface.co/spaces/farrell236/OCT_Segmentation_a2/resolve/main/app.py
- Command line
-
hf download hf://spaces/farrell236/OCT_Segmentation_a2/app.py
-
curl -L -o app.py https://huggingface.co/spaces/farrell236/OCT_Segmentation_a2/resolve/main/app.py
2.28 kB
| """Launch the Gradio OCT viewer locally or on Hugging Face Spaces.""" | |
| import argparse | |
| import os | |
| from pathlib import Path | |
| def main(): | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument( | |
| "--checkpoint", | |
| type=Path, | |
| default=Path(__file__).parent / "artifacts/checkpoint.pt", | |
| ) | |
| parser.add_argument( | |
| "--device", choices=["auto", "cpu", "cuda", "mps"], default="auto" | |
| ) | |
| parser.add_argument("--batch-size", type=int, default=1) | |
| parser.add_argument("--threads", type=int, default=2) | |
| parser.add_argument("--decode-workers", type=int, default=2) | |
| parser.add_argument("--timeout", type=int, default=1800) | |
| parser.add_argument( | |
| "--host", | |
| default=os.environ.get( | |
| "GRADIO_SERVER_NAME", | |
| "0.0.0.0" if os.environ.get("SPACE_ID") else "127.0.0.1", | |
| ), | |
| ) | |
| parser.add_argument( | |
| "--port", | |
| type=int, | |
| default=os.environ.get( | |
| "GRADIO_SERVER_PORT", "7860" if os.environ.get("SPACE_ID") else None | |
| ), | |
| ) | |
| parser.add_argument("--open", action="store_true", help="Open the app in a browser") | |
| args = parser.parse_args() | |
| if min(args.batch_size, args.threads, args.decode_workers, args.timeout) < 1: | |
| parser.error( | |
| "Batch size, threads, decode workers, and timeout must be positive" | |
| ) | |
| if not args.checkpoint.is_file(): | |
| parser.error(f"Checkpoint does not exist: {args.checkpoint}") | |
| if args.batch_size > 16: | |
| parser.error("The viewer batch size must be from 1 to 16") | |
| os.environ.setdefault("GRADIO_ANALYTICS_ENABLED", "False") | |
| from src.app import build_app | |
| from src.viewer import ENGINE | |
| ENGINE.checkpoint = args.checkpoint.resolve() | |
| ENGINE.threads = args.threads | |
| ENGINE.decode_workers = args.decode_workers | |
| ENGINE.timeout = args.timeout | |
| demo = build_app(device=args.device, batch_size=args.batch_size) | |
| demo.queue(max_size=12, default_concurrency_limit=1) | |
| demo.launch( | |
| server_name=args.host, | |
| server_port=args.port, | |
| inbrowser=args.open, | |
| share=False, | |
| show_error=False, | |
| blocked_paths=[str(Path(__file__).parent.resolve())], | |
| ) | |
| if __name__ == "__main__": | |
| main() | |