Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| def calculator(a, b, operation): | |
| if operation == "Add": | |
| return a + b | |
| elif operation == "Subtract": | |
| return a - b | |
| elif operation == "Multiply": | |
| return a * b | |
| elif operation == "Divide": | |
| return a / b if b != 0 else "Error: Division by zero" | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# 🧮 Simple Calculator") | |
| with gr.Row(): | |
| a = gr.Number(label="First Number") | |
| b = gr.Number(label="Second Number") | |
| operation = gr.Radio(["Add", "Subtract", "Multiply", "Divide"], label="Operation") | |
| result = gr.Textbox(label="Result") | |
| btn = gr.Button("Calculate") | |
| btn.click(calculator, inputs=[a, b, operation], outputs=result) | |
| demo.launch() | |