sashdev commited on
Commit
150c539
·
verified ·
1 Parent(s): b40dd3c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -20
app.py CHANGED
@@ -1,25 +1,23 @@
 
1
  import language_tool_python
2
- import gradio as gr
3
 
4
- # Initialize LanguageTool for English
5
- tool = language_tool_python.LanguageTool('en-US')
6
 
7
- # Function to correct grammar
8
- def grammar_correction(text):
9
- matches = tool.check(text)
10
- corrected_text = language_tool_python.utils.correct(text, matches)
11
- return corrected_text
12
 
13
- # Gradio interface for testing the grammar correction
14
- def main():
15
- iface = gr.Interface(
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
- if __name__ == "__main__":
25
- main()
 
 
 
 
 
 
 
 
 
 
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}