ai-calculator / app.py
asad231's picture
Update app.py
abd7af4 verified
raw
history blame
872 Bytes
import gradio as gr
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)}"
demo = gr.Interface(
fn=simple_calculator,
inputs=[
gr.Number(label="Enter First Number"),
gr.Number(label="Enter Second Number"),
gr.Radio(["+", "-", "*", "/"], label="Operation"),
],
outputs="text",
title="🧠 AI Calculator",
description="",
)
if __name__ == "__main__":
demo.launch()