File size: 725 Bytes
65f3040
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import gradio as gr

def letter_counter(word: str, letter: str) -> int:
    """
    計算 letter 在 word 中出現的次數。

    Args:
        word (str): 要搜尋的文字
        letter (str): 要計數的字元

    Returns:
        int: 出現次數
    """
    word = word.lower()
    letter = letter.lower()
    count = word.count(letter)
    return count

# 建立標準 Gradio 介面
app = gr.Interface(
    fn=letter_counter,
    inputs=["textbox", "textbox"],
    outputs="number",
    title="字母計數器",
    description="輸入文字與一個字母,計算該字母在文字中出現的次數"
)

# 啟動 Gradio 網頁介面與 MCP 伺服器
if __name__ == "__main__":
    app.launch(mcp_server=True)