"""Start the CTFast web app, locally or on the Hugging Face Space. The trained detector is downloaded from the model repo first if it is missing. """ import argparse DEFAULT_PORT = 7860 def main() -> None: """Load the detector once and serve the Control Centre page and the API.""" parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) parser.add_argument("--host", default="0.0.0.0") parser.add_argument("--port", type=int, default=DEFAULT_PORT) parser.add_argument("--device", default="cpu", help="cpu, or cuda for a local GPU") args = parser.parse_args() import uvicorn from ctfast import deploy from ctfast.detector import Detector from ctfast.web.server import create_app deploy.fetch_model(only_missing=True) uvicorn.run(create_app(Detector(args.device)), host=args.host, port=args.port) if __name__ == "__main__": main()