Spaces:
Runtime error
Runtime error
| # main.py | |
| from deepmultilingualpunctuation import PunctuationModel | |
| import re | |
| from fastapi import FastAPI | |
| from fastapi.responses import HTMLResponse, FileResponse | |
| app = FastAPI() | |
| async def root(): | |
| return FileResponse(path="static/index.html", media_type="text/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) | |
| 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} | |
| async def read_item(item_id): | |
| return {"item_id": item_id} | |