Spaces:
No application file
No application file
| import gradio as gr | |
| # Define the function to perform the calculation | |
| def calculate(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 num1 / num2 | |
| else: | |
| return "Cannot divide by zero" | |
| # Define the Gradio interface | |
| iface = gr.Interface( | |
| fn=calculate, # function to call | |
| inputs=[ | |
| gr.Number(label="Number 1"), # Input for first number | |
| gr.Number(label="Number 2"), # Input for second number | |
| gr.Dropdown( # Dropdown to select operation | |
| choices=["Add", "Subtract", "Multiply", "Divide"], | |
| label="Operation" | |
| ), | |
| ], | |
| outputs="text", # Output as text (result of the calculation) | |
| live=True # Optional: live update while typing | |
| ) | |
| # Launch the interface | |
| iface.launch() | |