Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| def addition_action(first, second): | |
| result = first + second | |
| return result | |
| def subtraction_action(first, second): | |
| result = first - second | |
| return result | |
| def product_action(first, second): | |
| result = first * second | |
| return result | |
| def division_action(first , second): | |
| if second != 0: | |
| result = first / second # Use float division for true division | |
| else: | |
| result = "Error: Division by zero" | |
| return result | |
| # Gradio Interface function | |
| def calculate(first, second, operation): | |
| if operation == "Addition": | |
| return addition_action(first, second) | |
| elif operation == "Subtraction": | |
| return subtraction_action(first, second) | |
| elif operation == "Multiplication": | |
| return product_action(first, second) | |
| elif operation == "Division": | |
| return division_action(first, second) | |
| else: | |
| return "Invalid Operation" | |
| # Gradio Interface setup | |
| operation_choices = ["Addition", "Subtraction", "Multiplication", "Division"] | |
| iface = gr.Interface( | |
| fn=calculate, | |
| inputs=[ | |
| gr.Number(label="First Value"), | |
| gr.Number(label="Second Value"), | |
| gr.Dropdown(choices=operation_choices, label="Operation") | |
| ], | |
| outputs="text", | |
| live=True | |
| ) | |
| iface.launch() | |