calculator / app.py
Bushra346's picture
Update app.py
2f02a14 verified
# app.py
import gradio as gr
# Define the calculator logic
def simple_calculator(num1, num2, operation):
try:
if operation == "+":
result = num1 + num2
elif operation == "-":
result = num1 - num2
elif operation == "*":
result = num1 * num2
elif operation == "/":
result = num1 / num2 if num2 != 0 else "∞ (Divide by Zero)"
else:
result = "Unknown operation"
return f"✅ Result: {result}"
except Exception as e:
return f"❌ Error: {str(e)}"
# Create Gradio interface
demo = gr.Interface(
fn=simple_calculator,
inputs=[
gr.Number(label="Enter First Number"),
gr.Number(label="Enter Second Number"),
gr.Radio(["+", "-", "*", "/"], label="Select Operation"),
],
outputs=gr.Textbox(label="Result"),
title="🧮 AI Calculator",
description="Perform basic math operations: Addition, Subtraction, Multiplication, and Division.",
allow_flagging="never",
theme="default"
)
if __name__ == "__main__":
demo.launch()