import gradio as gr def calculator(a, b, operation): try: a = float(a) b = float(b) 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 a / b else: return "Error: Division by zero" else: return "Invalid operation" except ValueError: return "Error: Invalid input" # Gradio Interface dropdown = gr.Dropdown(["Add", "Subtract", "Multiply", "Divide"], label="Operation") num1 = gr.Textbox(label="Enter first number", type="number") num2 = gr.Textbox(label="Enter second number", type="number") iface = gr.Interface( fn=calculator, inputs=[num1, num2, dropdown], outputs="text", title="Simple Calculator", description="Perform basic arithmetic operations. Enter two numbers and select an operation." ) iface.launch()