hackmebroo commited on
Commit
fdd67c5
·
verified ·
1 Parent(s): e167f94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -11
app.py CHANGED
@@ -9,19 +9,24 @@ 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 count_letter(arg1: str, arg2: str) -> str:
13
- """Counts how many times a specific letter appears in a given text.
14
  Args:
15
- arg1: The input text to search.
16
- arg2: The letter to count (e.g., 'a').
17
  """
18
- try:
19
- if len(arg2) != 1 or not arg2.isalpha():
20
- return "Error: arg2 must be a single alphabet letter."
21
- count = arg1.count(arg2)
22
- return f"The letter '{arg2}' appears {count} time(s) in the text."
23
- except Exception as e:
24
- return f"Error: {str(e)}"
 
 
 
 
 
25
 
26
  @tool
27
  def get_current_time_in_timezone(timezone: str) -> str:
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+ def most_common_letter(text: str, _: str) -> str:
13
+ """Finds the most common alphabet letter in the given text (case-insensitive).
14
  Args:
15
+ text: The input text to analyze.
16
+ _: Unused second argument.
17
  """
18
+ text = text.lower()
19
+ frequency = {}
20
+
21
+ for char in text:
22
+ if 'a' <= char <= 'z':
23
+ frequency[char] = frequency.get(char, 0) + 1
24
+
25
+ if not frequency:
26
+ return "No alphabet letters found in the input."
27
+
28
+ most_common = max(frequency.items(), key=lambda x: x[1])
29
+ return f"The most common letter is '{most_common[0]}' which appears {most_common[1]} time(s)."
30
 
31
  @tool
32
  def get_current_time_in_timezone(timezone: str) -> str: