| import gradio as gr | |
| from modal_app import app, square | |
| def compute_square(x): | |
| """Compute the square of a number. | |
| Args: | |
| x (float | int): The number to square. | |
| Returns: | |
| float: The square of the input number. | |
| """ | |
| with app.run(): | |
| return square.remote(float(x)) | |
| # Create a standard Gradio interface | |
| demo = gr.Interface( | |
| fn=compute_square, | |
| inputs=gr.Number(label="Enter a number"), | |
| outputs=gr.Number(label="Square of the number"), | |
| title="Compute Square using Modal", | |
| description="Enter a number to compute its square using a remote Modal function." | |
| ) | |
| # Launch both the Gradio web interface and the MCP server | |
| if __name__ == "__main__": | |
| demo.launch(mcp_server=True) | |