Spaces:
Sleeping
Sleeping
File size: 1,097 Bytes
f31d70b 2f02a14 735f774 f31d70b 2f02a14 f31d70b 2f02a14 f31d70b 735f774 2f02a14 735f774 2f02a14 735f774 2f02a14 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | # 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()
|