codeboosterstech commited on
Commit
7aced48
·
verified ·
1 Parent(s): 40e91ea

Update app.py via Space Creator Agent

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ```python
2
+ # Simple Calculator Example
3
+ import math
4
+ import gradio as gr
5
+
6
+ def add(a, b):
7
+ """Return the sum of two numbers."""
8
+ return a + b
9
+
10
+ def subtract(a, b):
11
+ """Return the difference of two numbers."""
12
+ return a - b
13
+
14
+ def multiply(a, b):
15
+ """Return the product of two numbers."""
16
+ return a * b
17
+
18
+ def divide(a, b):
19
+ """Return the quotient of two numbers."""
20
+ if b == 0:
21
+ return "Error: Cannot divide by zero"
22
+ return a / b
23
+
24
+ def calculator(a, b, operation):
25
+ """Perform the specified operation on two numbers."""
26
+ if operation == "Addition":
27
+ return add(a, b)
28
+ elif operation == "Subtraction":
29
+ return subtract(a, b)
30
+ elif operation == "Multiplication":
31
+ return multiply(a, b)
32
+ elif operation == "Division":
33
+ return divide(a, b)
34
+ else:
35
+ return "Error: Invalid operation"
36
+
37
+ demo = gr.Interface(
38
+ calculator,
39
+ [
40
+ gr.Number(label="Number 1"),
41
+ gr.Number(label="Number 2"),
42
+ gr.Radio(
43
+ choices=["Addition", "Subtraction", "Multiplication", "Division"],
44
+ label="Operation",
45
+ ),
46
+ ],
47
+ gr.Output(label="Result"),
48
+ title="Simple Calculator",
49
+ description="A simple calculator that performs basic arithmetic operations.",
50
+ )
51
+
52
+ if __name__ == "__main__":
53
+ demo.launch()
54
+ ```