|
from fastapi import FastAPI |
|
import language_tool_python |
|
|
|
app = FastAPI() |
|
|
|
|
|
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) |
|
|
|
errors = [{"message": match.message, "context": match.context, "suggestions": match.replacements} for match in matches] |
|
return {"errors": errors} |
|
|