Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
def calculator(num1, num2, operation):
|
| 4 |
+
if operation == "add":
|
| 5 |
+
return num1 + num2
|
| 6 |
+
elif operation == "subtract":
|
| 7 |
+
return num1 - num2
|
| 8 |
+
elif operation == "multiply":
|
| 9 |
+
return num1 * num2
|
| 10 |
+
elif operation == "divide":
|
| 11 |
+
if num2 == 0:
|
| 12 |
+
return "Error: Division by zero"
|
| 13 |
+
return num1 / num2
|
| 14 |
+
else:
|
| 15 |
+
return "Invalid operation"
|
| 16 |
+
|
| 17 |
+
# Define the Gradio interface
|
| 18 |
+
iface = gr.Interface(
|
| 19 |
+
fn=calculator,
|
| 20 |
+
inputs=[
|
| 21 |
+
gr.Number(label="Number 1"),
|
| 22 |
+
gr.Number(label="Number 2"),
|
| 23 |
+
gr.Radio(["add", "subtract", "multiply", "divide"], label="Operation")
|
| 24 |
+
],
|
| 25 |
+
outputs=gr.Textbox(label="Result"),
|
| 26 |
+
title="Simple Calculator",
|
| 27 |
+
description="A simple calculator to perform basic arithmetic operations."
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
# Launch the interface
|
| 31 |
+
iface.launch()
|