-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.py
58 lines (43 loc) · 1.37 KB
/
server.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# fastapi
from fastapi import FastAPI, HTTPException
from starlette.middleware.cors import CORSMiddleware
# lib
from transliterate.core import lat2cyr, Direction
# misc
import logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
app = FastAPI(
title="Imlo Project",
description="Imlo Project Description",
version="0.1.0",
)
origins = [
"http://tekshir.uz",
"https://tekshir.uz",
"http://localhost:3000",
"http://127.0.0.1:3000",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.post("/transliterate")
async def transliterate(content: str, direction: Direction):
logging.info(f"Transliterate direction -> {direction}")
data = {"status": "failure", "direction": direction}
if direction == Direction.lat2cyr:
result = await lat2cyr(content)
data = {"status": "success", "direction": direction, "data": result}
elif direction == Direction.cyr2lat:
raise HTTPException(status_code=400, detail="Not implemented yet.")
return data
@app.post("/spellchecker")
async def spellchecker(word: str):
raise HTTPException(status_code=400, detail="Not implemented yet.")
@app.post("/autocomplete")
async def autocomplete(word: str):
raise HTTPException(status_code=400, detail="Not implemented yet.")