File size: 905 Bytes
50c26c5 6777938 50c26c5 6777938 50c26c5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | """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()
|