Gas96 commited on
Commit
3a07c18
·
verified ·
1 Parent(s): ae7a494

First version of the tool.

Browse files

No test was performed at the current status.

Files changed (1) hide show
  1. app.py +24 -12
app.py CHANGED
@@ -4,20 +4,14 @@ import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
-
 
 
 
 
8
  from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
- @tool
12
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
15
- Args:
16
- arg1: the first argument
17
- arg2: the second argument
18
- """
19
- return "What magic will you build ?"
20
-
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
23
  """A tool that fetches the current local time in a specified timezone.
@@ -34,6 +28,24 @@ def get_current_time_in_timezone(timezone: str) -> str:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  final_answer = FinalAnswerTool()
38
 
39
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
@@ -55,7 +67,7 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
+ import nltk
8
+ import textstat
9
+ from nltk.tokenize import word_tokenize, sent_tokenize
10
+ from collections import Counter
11
+ nltk.download("punkt")
12
  from Gradio_UI import GradioUI
13
 
14
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
 
 
 
 
 
 
 
 
 
 
15
  @tool
16
  def get_current_time_in_timezone(timezone: str) -> str:
17
  """A tool that fetches the current local time in a specified timezone.
 
28
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
29
 
30
 
31
+ #Following my creation.
32
+ @tool
33
+ def text_analysis(text:str)-> str:
34
+ """A tool that analyzes a given text. It returns the word count, the number of sentences, the most used words, and the readability of the text.
35
+ Args:
36
+ text: A string with the text to analyze
37
+ """
38
+ try:
39
+ words = word_tokenize(text)
40
+ sentences = sent_tokenize(text)
41
+ word_count = len(words)
42
+ sentence_count = len(sentences)
43
+ reading_level = textstat.flesch_kincaid_grade(text)
44
+ most_common_words = Counter(words).most_common(5)
45
+ return f"I completed the analysis. The text has {word_count} words and {sentence_count} sentences. The reading level is {reading_level}. The 5 most common words are {most_common_words}"
46
+ except Exception as e:
47
+ return f"I could not complete the task. I got this error: {e}"
48
+
49
  final_answer = FinalAnswerTool()
50
 
51
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
 
67
 
68
  agent = CodeAgent(
69
  model=model,
70
+ tools=[final_answer, text_analysis, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
71
  max_steps=6,
72
  verbosity_level=1,
73
  grammar=None,