Spaces:
No application file
No application file
File size: 981 Bytes
cea1bca |
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 |
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()
|