Download app.py from Tarekt/mcp: direct link, hf CLI and curl.
- Browser
- Download file 1.68 kB
-
https://huggingface.co/spaces/Tarekt/mcp/resolve/main/app.py
- Command line
-
hf download hf://spaces/Tarekt/mcp/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Tarekt/mcp/resolve/main/app.py
1.68 kB
| import gradio as gr | |
| # MCP Server Functions | |
| def multiply_server(a, b): | |
| """Multiply two numbers""" | |
| try: | |
| result = float(a) * float(b) | |
| return f"Result: {a} ร {b} = {result}" | |
| except ValueError: | |
| return "Error: Please enter valid numbers" | |
| def hello_server(name): | |
| """Greet a user""" | |
| if name.strip(): | |
| return f"Hello, {name}! Welcome to the MCP server." | |
| else: | |
| return "Hello! Please enter your name." | |
| # Create Gradio Interface | |
| with gr.Blocks(title="Simple MCP Server", theme=gr.themes.Soft()) as demo: | |
| gr.Markdown("# ๐ Simple MCP Server\nTwo basic MCP servers: Multiply and Hello") | |
| with gr.Tabs(): | |
| # Multiply Server Tab | |
| with gr.Tab("โ๏ธ Multiply Server"): | |
| gr.Markdown("### Multiply two numbers") | |
| with gr.Row(): | |
| mult_a = gr.Number(label="First Number", value=5) | |
| mult_b = gr.Number(label="Second Number", value=3) | |
| mult_btn = gr.Button("Multiply", variant="primary") | |
| mult_output = gr.Textbox(label="Result", lines=2) | |
| mult_btn.click(multiply_server, inputs=[mult_a, mult_b], outputs=mult_output) | |
| # Hello Server Tab | |
| with gr.Tab("๐ Hello Server"): | |
| gr.Markdown("### Get a personalized greeting") | |
| hello_name = gr.Textbox(label="Your Name", placeholder="Enter your name") | |
| hello_btn = gr.Button("Say Hello", variant="primary") | |
| hello_output = gr.Textbox(label="Greeting", lines=2) | |
| hello_btn.click(hello_server, inputs=[hello_name], outputs=hello_output) | |
| if __name__ == "__main__": | |
| demo.launch(mcp_server=True) |