forked from brevia-ai/brevia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
32 lines (28 loc) · 937 Bytes
/
main.py
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
"""API endpoint definitions with FastAPI."""
from pathlib import Path
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
from brevia.routers.app_routers import add_routers
from brevia.utilities.openapi import metadata
meta = metadata(f'{Path(__file__).parent}/pyproject.toml')
app = FastAPI(**meta)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["POST"],
allow_headers=["*"],
)
add_routers(app)
if __name__ == '__main__':
run_opts = {
'reload': True,
'reload_excludes': ['*.log', './history/*'],
'reload_dirs': ['brevia/'],
}
ROOT_PATH = str(Path(__file__).parents[0])
log_config = f'{ROOT_PATH}/log.ini'
if Path(log_config).exists():
run_opts['log_config'] = log_config
run_opts['reload'] = False # avoid continuous `change detected` logs for now
uvicorn.run('main:app', **run_opts)