Spaces:
Runtime error
Runtime error
File size: 1,668 Bytes
c3c3a5e 24f6bf4 e867911 24f6bf4 c3c3a5e 24f6bf4 c3c3a5e |
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 |
""" 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)
|