codeboosterstech commited on
Commit
da22cbb
·
verified ·
1 Parent(s): 657e157

Update app.py via Space Creator Agent

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