Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ import pytz
|
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
from huggingface_hub import InferenceClient
|
|
|
8 |
|
9 |
from Gradio_UI import GradioUI
|
10 |
|
@@ -19,6 +20,30 @@ def my_custom_tool(arg1:int, arg2:str)-> str: #it's import to specify the return
|
|
19 |
"""
|
20 |
return arg2 * arg1
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
@tool
|
23 |
def get_current_time_in_timezone(timezone: str) -> str:
|
24 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
from huggingface_hub import InferenceClient
|
8 |
+
import language_tool_python
|
9 |
|
10 |
from Gradio_UI import GradioUI
|
11 |
|
|
|
20 |
"""
|
21 |
return arg2 * arg1
|
22 |
|
23 |
+
@tool
|
24 |
+
def correct_grammar(sentence: str) -> str:
|
25 |
+
"""A tool that checks and corrects grammatical errors in a given sentence.
|
26 |
+
|
27 |
+
Args:
|
28 |
+
sentence: A string containing the sentence to correct.
|
29 |
+
|
30 |
+
Returns:
|
31 |
+
A grammatically corrected version of the input sentence.
|
32 |
+
"""
|
33 |
+
try:
|
34 |
+
tool = language_tool_python.LanguageTool('en-US')
|
35 |
+
matches = tool.check(sentence)
|
36 |
+
corrected = language_tool_python.utils.correct(sentence, matches)
|
37 |
+
return corrected
|
38 |
+
except Exception as e:
|
39 |
+
return f"Error correcting sentence: {str(e)}"
|
40 |
+
|
41 |
+
# Example usage
|
42 |
+
if __name__ == "__main__":
|
43 |
+
test_sentence = "He go to school everyday."
|
44 |
+
print("Original:", test_sentence)
|
45 |
+
print("Corrected:", correct_grammar(test_sentence))
|
46 |
+
|
47 |
@tool
|
48 |
def get_current_time_in_timezone(timezone: str) -> str:
|
49 |
"""A tool that fetches the current local time in a specified timezone.
|