File size: 1,027 Bytes
59fb62a 9dbb134 59fb62a c1c8471 9dbb134 59fb62a c1c8471 9dbb134 59fb62a c1c8471 9dbb134 |
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 |
# -*- coding: utf-8 -*-
import json
from fastapi import APIRouter, Response
from pythainlp.util import (
bahttext as py_bahttext,
normalize as py_normalize,
tone_detector as py_tone_detector
)
router = APIRouter()
@router.post('/bahttext')
def bahttext(number: float):
"""
This api converts a number to Thai text and adds a suffix “บาท” (Baht).
"""
return Response(
json.dumps({"bahttext": py_bahttext(number)}, ensure_ascii=False),
media_type="application/json",
)
@router.post('/normalize')
def normalize(text: str):
"""
Normalize and clean Thai text
"""
return Response(
json.dumps({"text": py_normalize(text)}, ensure_ascii=False),
media_type="application/json",
)
@router.post('/tone_detector')
def tone_detector(syllable: str):
"""
Thai tone detector for word.
"""
return Response(
json.dumps({"tone": py_tone_detector(syllable)}, ensure_ascii=False),
media_type="application/json",
)
|