gperdrizet commited on
Commit
e66e891
·
unverified ·
1 Parent(s): 4dd70a8

Refactored interface HTML elements and tool functions.

Browse files
Files changed (3) hide show
  1. assets/html.py +11 -0
  2. functions/tools.py +18 -0
  3. rss_server.py +13 -42
assets/html.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ '''HTML elements for Gradio interface.'''
2
+
3
+ TITLE = (
4
+ '''
5
+ <center>
6
+ <h1>Letter counter</h1>
7
+ </center>
8
+ '''
9
+ )
10
+
11
+ DESCRIPTION = 'Enter text and a letter to count how many times the letter appears in the text.'
functions/tools.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ '''Tool functions for MCP server'''
2
+
3
+
4
+ def letter_counter(word, letter):
5
+ """
6
+ Count the number of occurrences of a letter in a word or text.
7
+
8
+ Args:
9
+ word (str): The input text to search through
10
+ letter (str): The letter to search for
11
+
12
+ Returns:
13
+ str: A message indicating how many times the letter appears
14
+ """
15
+ word = word.lower()
16
+ letter = letter.lower()
17
+ count = word.count(letter)
18
+ return count
rss_server.py CHANGED
@@ -1,58 +1,29 @@
1
  '''Main script to run gradio interface and MCP server.'''
2
 
3
  import gradio as gr
4
-
5
-
6
- def letter_counter(word, letter):
7
- """
8
- Count the number of occurrences of a letter in a word or text.
9
-
10
- Args:
11
- word (str): The input text to search through
12
- letter (str): The letter to search for
13
-
14
- Returns:
15
- str: A message indicating how many times the letter appears
16
- """
17
- word = word.lower()
18
- letter = letter.lower()
19
- count = word.count(letter)
20
- return count
21
-
22
- # demo = gr.Interface(
23
- # fn=letter_counter,
24
- # inputs=[gr.Textbox("strawberry"), gr.Textbox("r")],
25
- # outputs=[gr.Number()],
26
- # title="Letter Counter",
27
- # description="Enter text and a letter to count how many times the letter appears in the text."
28
- # )
29
-
30
- title=(
31
- """
32
- <center>
33
- <h1>Letter counter</h1>
34
- </center>
35
- """
36
- )
37
-
38
 
39
 
40
  with gr.Blocks() as demo:
41
 
42
  with gr.Row():
43
- gr.HTML(title)
44
 
45
- gr.Markdown("Enter text and a letter to count how many times the letter appears in the text.")
46
- word = gr.Textbox("strawberry", label="Text")
47
- letter = gr.Textbox("r", label='Word')
48
  output = gr.Number(label='Letter count')
49
  count_button = gr.Button('Count')
50
 
51
- count_button.click(
52
- fn=letter_counter,
53
- inputs=[word, letter],
54
  outputs=output,
55
  api_name='letter count'
56
  )
57
 
58
- demo.launch(mcp_server=True)
 
 
 
 
1
  '''Main script to run gradio interface and MCP server.'''
2
 
3
  import gradio as gr
4
+ import assets.html as html
5
+ from functions import tools as tool_funcs
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
 
8
  with gr.Blocks() as demo:
9
 
10
  with gr.Row():
11
+ gr.HTML(html.TITLE)
12
 
13
+ gr.Markdown(html.DESCRIPTION)
14
+ input_word = gr.Textbox('strawberry', label='Text')
15
+ target_letter = gr.Textbox('r', label='Word')
16
  output = gr.Number(label='Letter count')
17
  count_button = gr.Button('Count')
18
 
19
+ count_button.click( # pylint: disable=no-member
20
+ fn=tool_funcs.letter_counter,
21
+ inputs=[input_word, target_letter],
22
  outputs=output,
23
  api_name='letter count'
24
  )
25
 
26
+
27
+ if __name__ == '__main__':
28
+
29
+ demo.launch(mcp_server=True)