Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
def calculate(operation, num1, num2):
|
| 4 |
+
try:
|
| 5 |
+
num1 = int(num1)
|
| 6 |
+
num2 = int(num2)
|
| 7 |
+
except ValueError:
|
| 8 |
+
return "Invalid input"
|
| 9 |
+
|
| 10 |
+
if operation == 'Add':
|
| 11 |
+
return num1 + num2
|
| 12 |
+
elif operation == 'Subtract':
|
| 13 |
+
return num1 - num2
|
| 14 |
+
elif operation == 'Multiply':
|
| 15 |
+
return num1 * num2
|
| 16 |
+
elif operation == 'Divide':
|
| 17 |
+
return num1 / num2
|
| 18 |
+
else:
|
| 19 |
+
return 'Invalid operation'
|
| 20 |
+
|
| 21 |
+
operation_input = gr.inputs.Radio(["Add", "Subtract", "Multiply", "Divide"], default="Add")
|
| 22 |
+
num1_input = gr.inputs.Textbox(label="Enter first number")
|
| 23 |
+
num2_input = gr.inputs.Textbox(label="Enter second number")
|
| 24 |
+
|
| 25 |
+
gr.Interface(
|
| 26 |
+
calculate,
|
| 27 |
+
[operation_input, num1_input, num2_input],
|
| 28 |
+
gr.outputs.Textbox()
|
| 29 |
+
).launch(debug=True)
|