usmannaziir commited on
Commit
73a60e4
·
verified ·
1 Parent(s): 80a1dcb

Create app.py

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
+
3
+ def calculator(operation, a, b):
4
+ if operation == "Add":
5
+ return a + b
6
+ elif operation == "Subtract":
7
+ return a - b
8
+ elif operation == "Multiply":
9
+ return a * b
10
+ elif operation == "Divide":
11
+ if b == 0:
12
+ return "Cannot divide by zero"
13
+ return a / b
14
+ else:
15
+ return "Invalid operation"
16
+
17
+ demo = gr.Interface(
18
+ fn=calculator,
19
+ inputs=[
20
+ gr.Radio(["Add", "Subtract", "Multiply", "Divide"], label="Operation"),
21
+ gr.Number(label="Input A"),
22
+ gr.Number(label="Input B")
23
+ ],
24
+ outputs="text",
25
+ title="Demo Calculator",
26
+ description="Perform basic arithmetic operations."
27
+ )
28
+
29
+ if __name__ == "__main__":
30
+ demo.launch()