aboutsummaryrefslogtreecommitdiffstats
path: root/cargo/cargo.py
blob: 7957cd9ce6250b22fb799d3da734e74db47da93a (plain) (blame)
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
#!/usr/bin/env python3
"""Cargo is meant to server as a file/server downloader service."""
import http.server
import os
import socketserver

import huggingface_hub as hh


# https://huggingface.co/docs/huggingface_hub/how-to-downstream
def download(path: str = ".") -> None:
    """Download the required models from huggingface."""
    bart_pretrained = hh.hf_hub_url(
        "sshleifer/distilbart-cnn-12-6", filename="config.json"
    )
    hh.cached_download(bart_pretrained)


def serve() -> None:
    """Startup a simple http file server."""
    handler = http.server.SimpleHTTPRequestHandler
    port_number = os.environ["SERVER_PORT"]

    download(os.environ["SERVER_VAULT"])
    with socketserver.TCPServer(("", int(port_number)), handler) as httpd:
        httpd.serve_forever()


if __name__ == "__main__":
    serve()