Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| def calculator(num1, num2, operation): | |
| if operation == "add": | |
| return num1 + num2 | |
| elif operation == "subtract": | |
| return num1 - num2 | |
| elif operation == "multiply": | |
| return num1 * num2 | |
| elif operation == "divide": | |
| if num2 == 0: | |
| return "Error: Division by zero" | |
| return num1 / num2 | |
| else: | |
| return "Invalid operation" | |
| # Define the Gradio interface | |
| iface = gr.Interface( | |
| fn=calculator, | |
| inputs=[ | |
| gr.Number(label="Number 1"), | |
| gr.Number(label="Number 2"), | |
| gr.Radio(["add", "subtract", "multiply", "divide"], label="Operation") | |
| ], | |
| outputs=gr.Textbox(label="Result"), | |
| title="Simple Calculator", | |
| description="A simple calculator to perform basic arithmetic operations." | |
| ) | |
| # Launch the interface | |
| iface.launch() |