Spaces:
Configuration error
Configuration error
| ```python | |
| # Simple Calculator Example | |
| import math | |
| import gradio as gr | |
| def add(a, b): | |
| """Add two numbers""" | |
| return a + b | |
| def subtract(a, b): | |
| """Subtract two numbers""" | |
| return a - b | |
| def multiply(a, b): | |
| """Multiply two numbers""" | |
| return a * b | |
| def divide(a, b): | |
| """Divide two numbers""" | |
| if b == 0: | |
| return "Error: Cannot divide by zero" | |
| 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"], | |
| label="Operation", | |
| type="value", | |
| ), | |
| ], | |
| "text", | |
| title="Simple Calculator", | |
| description="A simple calculator that performs basic arithmetic operations", | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |
| ``` |