iamramzan commited on
Commit
bc7746c
·
verified ·
1 Parent(s): 04a21b2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ from transformers import pipeline
4
+
5
+ def calculator(num1, operation, num2):
6
+ if operation == "add":
7
+ return num1 + num2
8
+ elif operation == "subtract":
9
+ return num1 - num2
10
+ elif operation == "multiply":
11
+ return num1 * num2
12
+ elif operation == "divide":
13
+ if num2 == 0:
14
+ raise gr.Error("Cannot divide by zero!")
15
+ return num1 / num2
16
+
17
+ demo = gr.Interface(
18
+ calculator,
19
+ [
20
+ "number",
21
+ gr.Radio(["add", "subtract", "multiply", "divide"]),
22
+ "number"
23
+ ],
24
+ "number",
25
+ examples=[
26
+ [45, "add", 3],
27
+ [3.14, "divide", 2],
28
+ [144, "multiply", 2.5],
29
+ [0, "subtract", 1.2],
30
+ ],
31
+ title="Shaheen Calculator",
32
+ description="Here's a sample toy calculator.",
33
+ )
34
+
35
+ demo.launch(inline = False)