Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,23 @@
|
|
|
|
1 |
import language_tool_python
|
2 |
-
import gradio as gr
|
3 |
|
4 |
-
|
5 |
-
tool = language_tool_python.LanguageTool('en-US')
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
-
matches = tool.check(text)
|
10 |
-
corrected_text = language_tool_python.utils.correct(text, matches)
|
11 |
-
return corrected_text
|
12 |
|
13 |
-
|
14 |
-
def
|
15 |
-
|
16 |
-
fn=grammar_correction,
|
17 |
-
inputs="text",
|
18 |
-
outputs="text",
|
19 |
-
title="Grammar Correction Tool",
|
20 |
-
description="Enter text to correct grammar and spelling errors."
|
21 |
-
)
|
22 |
-
iface.launch()
|
23 |
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
import language_tool_python
|
|
|
3 |
|
4 |
+
app = FastAPI()
|
|
|
5 |
|
6 |
+
# Initialize the LanguageTool instance for English
|
7 |
+
tool = language_tool_python.LanguageTool('en-US')
|
|
|
|
|
|
|
8 |
|
9 |
+
@app.get("/")
|
10 |
+
def greet():
|
11 |
+
return {"message": "Hello, World!"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
+
@app.post("/check")
|
14 |
+
def check_text(text: str):
|
15 |
+
"""
|
16 |
+
This endpoint checks grammar and spelling of the input text.
|
17 |
+
:param text: The text to be checked
|
18 |
+
:return: A list of grammar and spelling mistakes
|
19 |
+
"""
|
20 |
+
matches = tool.check(text)
|
21 |
+
# Convert matches to a more readable format
|
22 |
+
errors = [{"message": match.message, "context": match.context, "suggestions": match.replacements} for match in matches]
|
23 |
+
return {"errors": errors}
|