| import gradio as gr |
|
|
| def calculator(num1, num2, operation): |
| if operation == "Add": |
| return num1 + num2 |
| elif operation == "Subtract": |
| return num1 - num2 |
| elif operation == "Multiply": |
| return num1 * num2 |
| elif operation == "Divide": |
| if num2 == 0: |
| return "Error: Division by zero!" |
| return num1 / num2 |
| else: |
| return "Invalid operation" |
|
|
| app = gr.Interface( |
| fn=calculator, |
| inputs=[ |
| gr.Number(label="First Number"), |
| gr.Number(label="Second Number"), |
| gr.Dropdown(["Add", "Subtract", "Multiply", "Divide"], label="Operation") |
| ], |
| outputs=gr.Textbox(label="Result"), |
| title="Simple Calculator", |
| description="Enter two numbers and choose an operation." |
| ) |
|
|
| if __name__ == "__main__": |
| app.launch() |
|
|