minicalculator / app.py
Mrym834's picture
Update app.py
19f477f verified
Raw
History Blame Contribute Delete
881 Bytes
import gradio as gr
# Define a simple calculator function
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":
if b == 0:
return "Error: Division by zero"
return a / b
# Create the Gradio interface
with gr.Blocks() as demo:
gr.Markdown("## 🧮 Mini Calculator")
with gr.Row():
a = gr.Number(label="Number 1")
b = gr.Number(label="Number 2")
operation = gr.Radio(["Add", "Subtract", "Multiply", "Divide"], label="Operation", value="Add")
result = gr.Textbox(label="Result", interactive=False)
calculate_btn = gr.Button("Calculate")
calculate_btn.click(calculator, inputs=[a, b, operation], outputs=result)
# Launch the app
demo.launch()