Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
def addition_action(first, second):
|
| 4 |
+
result = first + second
|
| 5 |
+
return result
|
| 6 |
+
|
| 7 |
+
def subtraction_action(first, second):
|
| 8 |
+
result = first - second
|
| 9 |
+
return result
|
| 10 |
+
|
| 11 |
+
def product_action(first, second):
|
| 12 |
+
result = first * second
|
| 13 |
+
return result
|
| 14 |
+
|
| 15 |
+
def division_action(first , second):
|
| 16 |
+
if second != 0:
|
| 17 |
+
result = first / second # Use float division for true division
|
| 18 |
+
else:
|
| 19 |
+
result = "Error: Division by zero"
|
| 20 |
+
return result
|
| 21 |
+
|
| 22 |
+
# Gradio Interface function
|
| 23 |
+
def calculate(first, second, operation):
|
| 24 |
+
if operation == "Addition":
|
| 25 |
+
return addition_action(first, second)
|
| 26 |
+
elif operation == "Subtraction":
|
| 27 |
+
return subtraction_action(first, second)
|
| 28 |
+
elif operation == "Multiplication":
|
| 29 |
+
return product_action(first, second)
|
| 30 |
+
elif operation == "Division":
|
| 31 |
+
return division_action(first, second)
|
| 32 |
+
else:
|
| 33 |
+
return "Invalid Operation"
|
| 34 |
+
|
| 35 |
+
# Gradio Interface setup
|
| 36 |
+
operation_choices = ["Addition", "Subtraction", "Multiplication", "Division"]
|
| 37 |
+
|
| 38 |
+
iface = gr.Interface(
|
| 39 |
+
fn=calculate,
|
| 40 |
+
inputs=[
|
| 41 |
+
gr.Number(label="First Value"),
|
| 42 |
+
gr.Number(label="Second Value"),
|
| 43 |
+
gr.Dropdown(choices=operation_choices, label="Operation")
|
| 44 |
+
],
|
| 45 |
+
outputs="text",
|
| 46 |
+
live=True
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
iface.launch()
|