File size: 2,237 Bytes
8c22399
d2b7e94
8c22399
627d3d7
 
d2b7e94
 
 
 
 
 
 
 
8c22399
 
d2b7e94
8c22399
 
d2b7e94
8c22399
01e655b
8c22399
 
 
 
 
 
 
 
 
 
 
 
 
627d3d7
8c22399
 
 
627d3d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c22399
 
627d3d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import logging
import os

from modules.ffmpeg_env import setup_ffmpeg_path

try:
    setup_ffmpeg_path()
    logging.basicConfig(
        level=os.getenv("LOG_LEVEL", "INFO"),
        format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
    )
except BaseException:
    pass

import argparse

import uvicorn

from modules.api.api_setup import setup_api_args, setup_model_args, setup_uvicon_args
from modules.utils import env

logger = logging.getLogger(__name__)

if __name__ == "__main__":
    import dotenv

    dotenv.load_dotenv(
        dotenv_path=os.getenv("ENV_FILE", ".env.api"),
    )
    parser = argparse.ArgumentParser(
        description="Start the FastAPI server with command line arguments"
    )
    setup_api_args(parser)
    setup_model_args(parser)
    setup_uvicon_args(parser=parser)

    args = parser.parse_args()

    host = env.get_and_update_env(args, "host", "0.0.0.0", str)
    port = env.get_and_update_env(args, "port", 7870, int)
    reload = env.get_and_update_env(args, "reload", False, bool)
    workers = env.get_and_update_env(args, "workers", 1, int)
    log_level = env.get_and_update_env(args, "log_level", "info", str)
    access_log = env.get_and_update_env(args, "access_log", True, bool)
    proxy_headers = env.get_and_update_env(args, "proxy_headers", True, bool)
    timeout_keep_alive = env.get_and_update_env(args, "timeout_keep_alive", 5, int)
    timeout_graceful_shutdown = env.get_and_update_env(
        args, "timeout_graceful_shutdown", 0, int
    )
    ssl_keyfile = env.get_and_update_env(args, "ssl_keyfile", None, str)
    ssl_certfile = env.get_and_update_env(args, "ssl_certfile", None, str)
    ssl_keyfile_password = env.get_and_update_env(
        args, "ssl_keyfile_password", None, str
    )

    uvicorn.run(
        "modules.api.worker:app",
        host=host,
        port=port,
        reload=reload,
        workers=workers,
        log_level=log_level,
        access_log=access_log,
        proxy_headers=proxy_headers,
        timeout_keep_alive=timeout_keep_alive,
        timeout_graceful_shutdown=timeout_graceful_shutdown,
        ssl_keyfile=ssl_keyfile,
        ssl_certfile=ssl_certfile,
        ssl_keyfile_password=ssl_keyfile_password,
    )