Spaces:
Sleeping
Sleeping
Commit
·
0e54c10
1
Parent(s):
74d385c
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
def calculator(operator, num1, num2):
|
| 4 |
+
if operator == "+":
|
| 5 |
+
result = num1 + num2
|
| 6 |
+
|
| 7 |
+
elif operator == "-":
|
| 8 |
+
result = num1 - num2
|
| 9 |
+
|
| 10 |
+
elif operator == "*":
|
| 11 |
+
result = num1 * num2
|
| 12 |
+
|
| 13 |
+
elif operator == "/":
|
| 14 |
+
if num2 != 0:
|
| 15 |
+
result = num1/num2
|
| 16 |
+
else:
|
| 17 |
+
return "Error, Division by zero not allowed"
|
| 18 |
+
|
| 19 |
+
else:
|
| 20 |
+
return f"Error, {operator} is invalid. Please try again "
|
| 21 |
+
|
| 22 |
+
return result
|
| 23 |
+
|
| 24 |
+
iface = gr.Interface( fn=calculator,
|
| 25 |
+
inputs=["text","number","number"],
|
| 26 |
+
outputs="text")
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
iface.launch(share=True)
|
| 30 |
+
|