Javier-Jimenez99 commited on
Commit
92cc575
·
1 Parent(s): 7786921

Add more tools

Browse files
Files changed (1) hide show
  1. app.py +42 -6
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import gradio as gr
2
 
 
3
  def letter_counter(word, letter):
4
  """
5
  Count the number of occurrences of a letter in a word or text.
@@ -16,12 +17,47 @@ def letter_counter(word, letter):
16
  count = word.count(letter)
17
  return count
18
 
19
- demo = gr.Interface(
20
- fn=letter_counter,
21
- inputs=[gr.Textbox("strawberry"), gr.Textbox("r")],
22
- outputs=[gr.Number()],
23
- title="Letter Counter",
24
- description="Enter text and a letter to count how many times the letter appears in the text."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  )
26
 
27
  demo.launch(mcp_server=True)
 
1
  import gradio as gr
2
 
3
+ # === TOOLS ===
4
  def letter_counter(word, letter):
5
  """
6
  Count the number of occurrences of a letter in a word or text.
 
17
  count = word.count(letter)
18
  return count
19
 
20
+ def prime_factors(n):
21
+ """
22
+ Compute the prime factorization of a positive integer.
23
+ Args:
24
+ n (int): The integer to factorize. Must be greater than 1.
25
+ Returns:
26
+ List[int]: A list of prime factors in ascending order.
27
+ Raises:
28
+ ValueError: If n is not greater than 1.
29
+ """
30
+ n = int(n)
31
+ if n <= 1:
32
+ raise ValueError("Input must be an integer greater than 1.")
33
+
34
+ factors = []
35
+ while n % 2 == 0:
36
+ factors.append(2)
37
+ n //= 2
38
+
39
+ divisor = 3
40
+ while divisor * divisor <= n:
41
+ while n % divisor == 0:
42
+ factors.append(divisor)
43
+ n //= divisor
44
+ divisor += 2
45
+
46
+ if n > 1:
47
+ factors.append(n)
48
+
49
+ return factors
50
+
51
+ # === GRADIO INTERFACE ===
52
+ demo = gr.TabbedInterface(
53
+ [
54
+ gr.Interface(letter_counter, [gr.Textbox(), gr.Textbox()], gr.Textbox(), api_name="letter_counter"),
55
+ gr.Interface(prime_factors, gr.Number(), gr.JSON(), api_name="prime_factors"),
56
+ ],
57
+ [
58
+ "Letter Counter",
59
+ "Prime Factors"
60
+ ]
61
  )
62
 
63
  demo.launch(mcp_server=True)