Mohamed90 commited on
Commit
5c5114a
1 Parent(s): 68cf94c

initial commit

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ if num2 == 0:
12
+ raise gr.Error("Cannot divide by zero!")
13
+ return num1 / num2
14
+
15
+ demo = gr.Interface(
16
+ calculator,
17
+ [
18
+ "number",
19
+ gr.Radio(["add", "subtract", "multiply", "divide"]),
20
+ "number"
21
+ ],
22
+ "number",
23
+ examples=[
24
+ [5, "add", 3],
25
+ [4, "divide", 2],
26
+ [-4, "multiply", 2.5],
27
+ [0, "subtract", 1.2],
28
+ ],
29
+ title="Toy Calculator",
30
+ description="Here's a sample toy calculator. Allows you to calculate things like $2+2=4$",
31
+ )
32
+ demo.launch()