Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| def calculator(num1, op, num2): | |
| if op == "+": | |
| result = num1 + num2 | |
| elif op == "-": | |
| result = num1 - num2 | |
| elif op == "*": | |
| result = num1 * num2 | |
| elif op == "/": | |
| if num2 == 0: | |
| return "Error: Division by zero" | |
| result = num1 / num2 | |
| else: | |
| return "Invalid operator" | |
| return result | |
| demo = gr.Interface( | |
| calculator, | |
| [ | |
| gr.Number(label="First Number"), | |
| gr.Dropdown(label="Operator", choices=["+", "-", "*", "/"]), | |
| gr.Number(label="Second Number") | |
| ], | |
| gr.Textbox(label="Result"), | |
| title="Simple Calculator", | |
| description="A simple calculator that performs basic arithmetic operations." | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |