""" main api file """ from fastapi.responses import HTMLResponse from fastapi.staticfiles import StaticFiles from fastapi.templating import Jinja2Templates from fastapi import FastAPI, Request from fastapi.middleware.cors import CORSMiddleware from app.routers import routes """ initialize app with openapi configurations """ app = FastAPI( title="Mother Tongue Voice Matcher", version="0.0.5", servers=[ { "url": "http://127.0.0.1:8000/api/v1", "description": "Local Server", }, { "url": "https://r3vibe-mother-tongue.hf.space/api/v1", "description": "Huggingface Server", } ], root_path="/api/v1", root_path_in_servers=False, ) # cors policy origins = [ "http://localhost", "http://localhost:8080", "http://localhost:3000", "http://localhost:5173", "http://127.0.0.1", "http://127.0.0.1:8080", "http://127.0.0.1:3000", "http://127.0.0.1:5173", "https://r3vibe-mother-tongue.hf.space", ] app.add_middleware( CORSMiddleware, allow_origins=origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # mount the static folder app.mount("/static", StaticFiles(directory="app/static"), name="static") # mount the templets folder templates = Jinja2Templates(directory="app/templates") @app.get("/", response_class=HTMLResponse, include_in_schema=False) async def root(request: Request): """set the root to show a html welcome page""" return templates.TemplateResponse(request=request, name="index.html") # include all the other api endpoints app.include_router(routes.router)