File size: 1,285 Bytes
29714d1
568c88a
 
29714d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
afb73c0
 
568c88a
afb73c0
568c88a
 
 
 
 
 
 
 
 
 
 
 
 
29714d1
afb73c0
29714d1
 
 
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
# main.py
from deepmultilingualpunctuation import PunctuationModel
import re

from fastapi import FastAPI
from fastapi.responses import HTMLResponse, FileResponse

app = FastAPI()


@app.get("/")
async def root():
    return FileResponse(path="static/index.html", media_type="text/html")

@app.get("/html")
async def root():
    """Basic HTML response."""
    body = (
        "<html>"
        "<body style='padding: 10px;'>"
        "<h1>Welcome to the API</h1>"
    "<div>"
        "Check the docs: <a href='/docs'>here</a>"
        "</div>"
        "</body>"
        "</html>"
    )

    return HTMLResponse(content=body)

@app.get("/api/{input_text}")
async def cal_api(input_text):

    #input_text = "my name is clara i live in berkeley california"

    model = PunctuationModel()
    output_text = model.restore_punctuation(input_text)

    split_text = output_text.split('. ')
    pcnt_file_cr = '.\n'.join(split_text)
    
    regex1 = r"\bi\b"
    regex2 = r"(?<=[.?!;])\s*\w"
    regex3 = r"^\w"
    pcnt_file_cr_cap = re.sub(regex3, lambda x: x.group().upper(), re.sub(regex2, lambda x: x.group().upper(), re.sub(regex1, "I", pcnt_file_cr)))

    return {"data": pcnt_file_cr_cap}

@app.get("/item/{item_id}")
async def read_item(item_id):
    return {"item_id": item_id}