import gradio as gr def letter_counter(word: str, letter: str) -> int: """ Count the number of occurrences of a letter in a word or text. Args: word (str): The input text to search through letter (str): The letter to search for Returns: int: The number of times the letter appears in the text """ word = word.lower() letter = letter.lower() count = word.count(letter) return count def word_length_calculator(text: str) -> int: """ Calculate the length of the input text. Args: text (str): The input text to measure Returns: int: The number of characters in the text """ return len(text) def text_reverser(text: str) -> str: """ Reverse the input text. Args: text (str): The text to reverse Returns: str: The reversed text """ return text[::-1] def word_counter(text: str) -> int: """ Count the number of words in the input text. Args: text (str): The input text to count words from Returns: int: The number of words in the text """ return len(text.split()) # Create individual interfaces for each function letter_counter_interface = gr.Interface( fn=letter_counter, inputs=["textbox", "textbox"], outputs="number", title="Letter Counter", description="Count occurrences of a specific letter in text" ) word_length_interface = gr.Interface( fn=word_length_calculator, inputs="textbox", outputs="number", title="Text Length Calculator", description="Calculate the length of input text" ) text_reverser_interface = gr.Interface( fn=text_reverser, inputs="textbox", outputs="textbox", title="Text Reverser", description="Reverse the input text" ) word_counter_interface = gr.Interface( fn=word_counter, inputs="textbox", outputs="number", title="Word Counter", description="Count the number of words in text" ) # Combine all interfaces into a tabbed interface demo = gr.TabbedInterface( [letter_counter_interface, word_length_interface, text_reverser_interface, word_counter_interface], ["Letter Counter", "Text Length", "Text Reverser", "Word Counter"], title="Text Processing MCP Server" ) # For Hugging Face Spaces - remove the if __name__ == "__main__": wrapper demo.launch(mcp_server=True)