LTP / app.py
sashdev's picture
Update app.py
150c539 verified
raw
history blame
698 Bytes
from fastapi import FastAPI
import language_tool_python
app = FastAPI()
# Initialize the LanguageTool instance for English
tool = language_tool_python.LanguageTool('en-US')
@app.get("/")
def greet():
return {"message": "Hello, World!"}
@app.post("/check")
def check_text(text: str):
"""
This endpoint checks grammar and spelling of the input text.
:param text: The text to be checked
:return: A list of grammar and spelling mistakes
"""
matches = tool.check(text)
# Convert matches to a more readable format
errors = [{"message": match.message, "context": match.context, "suggestions": match.replacements} for match in matches]
return {"errors": errors}