radi02 commited on
Commit
9447bb7
1 Parent(s): 6197059

calculator_gradio

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ def calculator(num1, operation, num2):
3
+ if operation == "add":
4
+ return num1 + num2
5
+ elif operation == "subtract":
6
+ return num1 - num2
7
+ elif operation == "multiply":
8
+ return num1 * num2
9
+ elif operation == "divide":
10
+ return num1 / num2
11
+ elif operation == "power":
12
+ return num1 ** num2
13
+
14
+ demo = gr.Interface(
15
+ calculator,
16
+ inputs=[gr.Number(0), gr.Radio(["add", "subtract", "multiply", "divide","power"]), "number"],
17
+ outputs="number",
18
+ examples=[
19
+ [5, "add", 3],
20
+ [4, "divide", 2],
21
+ [-4, "multiply", 2.5],
22
+ [0, "subtract", 1.2],
23
+ [6,"power",2],
24
+ ],
25
+ title="calculator!!",
26
+ description="heres a sample toy calculator. enjoy!",
27
+ flagging_options=["this", "or", "that"],
28
+ )
29
+
30
+ demo.launch(share=True)