Spaces:
Runtime error
Runtime error
| import os | |
| import uvicorn | |
| from fastapi import FastAPI | |
| from fastapi.responses import HTMLResponse | |
| from fastapi.staticfiles import StaticFiles | |
| from app.config import settings | |
| from app.manage import configure_app | |
| from app.utils.constants import APP_DESCRIPTION, APP_NAME, APP_VERSION, DOCS_URL, OPENAPI_URL, STATIC_DIR | |
| def initialize_app(): | |
| """Initializes the app by adding required configurations using configure_app | |
| Returns: | |
| app: returns configured app's FastAPI instance. | |
| """ | |
| fastapi_app = FastAPI(title=APP_NAME, version=APP_VERSION, description=APP_DESCRIPTION) | |
| # app configuration - one time | |
| configure_app(fastapi_app) | |
| # Mount the static folder | |
| fastapi_app.mount( | |
| "/static", | |
| StaticFiles(directory=STATIC_DIR), | |
| name="static", | |
| ) | |
| async def read_index(): | |
| with open(os.path.join(STATIC_DIR, "index.html")) as f: | |
| return HTMLResponse(content=f.read(), status_code=200) | |
| return fastapi_app | |
| # initialize app at the end | |
| server = initialize_app() | |
| def start(): | |
| uvicorn.run(server, host="0.0.0.0", port=8000) | |
| if __name__ == "__main__": | |
| start() | |