Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| def add(a, b): | |
| return a + b | |
| def subtract(a, b): | |
| return a - b | |
| def multiply(a, b): | |
| return a * b | |
| def divide(a, b): | |
| if b == 0: | |
| return "Error: Division by zero is not allowed" | |
| return a / b | |
| def calculator(num1, num2, operation): | |
| if operation == "Add": | |
| return add(num1, num2) | |
| elif operation == "Subtract": | |
| return subtract(num1, num2) | |
| elif operation == "Multiply": | |
| return multiply(num1, num2) | |
| elif operation == "Divide": | |
| return divide(num1, num2) | |
| demo = gr.Interface( | |
| calculator, | |
| [ | |
| gr.Number(label="Number 1"), | |
| gr.Number(label="Number 2"), | |
| gr.Radio( | |
| choices=["Add", "Subtract", "Multiply", "Divide"], | |
| type="value", | |
| label="Operation", | |
| ), | |
| ], | |
| "text", | |
| title="Basic Calculator", | |
| description="A simple calculator that performs basic arithmetic operations.", | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |