Usually3 commited on
Commit
53403c1
·
1 Parent(s): 913617c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ def calculator(num1, operation, num2):
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
+ return num1 / num2
12
+ elif operation == "square":
13
+ return num1 * num1
14
+ elif operation == "cube":
15
+ return num1 * num1 * num1
16
+
17
+
18
+ demo = gr.Interface(
19
+ fn=calculator,
20
+ inputs=[
21
+ gr.Number(value=4),
22
+ gr.Radio(["add", "subtract", "multiply", "divide","square","cube"]),
23
+ "number"
24
+ ],
25
+ outputs="number",
26
+ examples=[
27
+ [5, "add", 3],
28
+ [4, "divide", 2],
29
+ [-4, "multiply", 2.5],
30
+ [0, "subtract", 1.2],
31
+ ],
32
+ title="Scientific Calculator",
33
+ description="Here's a sample scientific calculator. Enjoy! Code by: Improved by: Usually3
34
+ )
35
+
36
+ demo.launch()