generated from Lotus-King-Research/New-Repository-Template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
35 lines (28 loc) · 967 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
33
34
35
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
import bophono
from starlette.middleware.cors import CORSMiddleware
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
templates = Jinja2Templates(directory="templates")
@app.get("/", response_class=HTMLResponse)
async def get_root(request: Request):
return templates.TemplateResponse("index.html", {"request": request})
@app.get("/phonetize")
async def phonetize_endpoint_get(string: str):
return phonetize(string)
@app.post("/phonetize")
async def phonetize_endpoint_post(string: str):
return phonetize(string)
def phonetize(string):
options = {'aspirateLowTones': False}
phon = bophono.UnicodeToApi(schema="LKT", options=options)
phonetic = phon.get_api(string)
return {"phonetic": phonetic}