alihmaou commited on
Commit
a4058ae
·
verified ·
1 Parent(s): b0a9f5c

Deploy tools/strawberry_counter.py via Meta-MCP

Browse files
Files changed (1) hide show
  1. tools/strawberry_counter.py +43 -0
tools/strawberry_counter.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import json
3
+ from PIL import Image
4
+ import numpy as np
5
+
6
+ # --- User Defined Logic ---
7
+ import re
8
+
9
+ def strawberry_counter(text: str) -> str:
10
+ """
11
+ Counts how many times the word 'strawberry' appears in the provided text.
12
+
13
+ The search is case-insensitive and returns a user-friendly message with the total count.
14
+
15
+ Args:
16
+ text (str): The input text in which to count occurrences of 'strawberry'.
17
+
18
+ Returns:
19
+ str: A message stating how many times 'strawberry' was found in the text.
20
+ """
21
+ if not isinstance(text, str):
22
+ return "Please provide a valid text input."
23
+
24
+ # Case-insensitive count using regex
25
+ matches = re.findall(r'strawberry', text, flags=re.IGNORECASE)
26
+ count = len(matches)
27
+
28
+ if count == 0:
29
+ return "No strawberries found in your text. 🍓"
30
+ elif count == 1:
31
+ return "Found 1 strawberry in your text! 🍓"
32
+ else:
33
+ return f"Found {count} strawberries in your text! 🍓"
34
+
35
+ # --- Interface Factory ---
36
+ def create_interface():
37
+ return gr.Interface(
38
+ fn=strawberry_counter,
39
+ inputs=[gr.Textbox(label=k) for k in ['text']],
40
+ outputs=gr.Textbox(label="Displays the number of times 'strawberry' appears in the text"),
41
+ title="strawberry-counter",
42
+ description="Auto-generated tool: strawberry-counter"
43
+ )