File size: 698 Bytes
150c539 a3f6cfb 150c539 a3f6cfb 150c539 a3f6cfb 150c539 a3f6cfb 150c539 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
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}
|