Spaces:
No application file
No application file
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
# Define the function to perform the calculation
|
4 |
+
def calculate(num1, num2, operation):
|
5 |
+
if operation == 'Add':
|
6 |
+
return num1 + num2
|
7 |
+
elif operation == 'Subtract':
|
8 |
+
return num1 - num2
|
9 |
+
elif operation == 'Multiply':
|
10 |
+
return num1 * num2
|
11 |
+
elif operation == 'Divide':
|
12 |
+
if num2 != 0:
|
13 |
+
return num1 / num2
|
14 |
+
else:
|
15 |
+
return "Cannot divide by zero"
|
16 |
+
|
17 |
+
# Define the Gradio interface
|
18 |
+
iface = gr.Interface(
|
19 |
+
fn=calculate, # function to call
|
20 |
+
inputs=[
|
21 |
+
gr.Number(label="Number 1"), # Input for first number
|
22 |
+
gr.Number(label="Number 2"), # Input for second number
|
23 |
+
gr.Dropdown( # Dropdown to select operation
|
24 |
+
choices=["Add", "Subtract", "Multiply", "Divide"],
|
25 |
+
label="Operation"
|
26 |
+
),
|
27 |
+
],
|
28 |
+
outputs="text", # Output as text (result of the calculation)
|
29 |
+
live=True # Optional: live update while typing
|
30 |
+
)
|
31 |
+
|
32 |
+
# Launch the interface
|
33 |
+
iface.launch()
|