ysharma HF Staff commited on
Commit
d42173e
·
1 Parent(s): 47e1b23
Files changed (1) hide show
  1. app.py +23 -27
app.py CHANGED
@@ -1,32 +1,28 @@
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()
 
1
  import gradio as gr
2
 
3
+ demo = gr.Blocks()
 
 
 
 
 
 
 
 
 
 
4
 
5
+ def dummy(tb, sl):
6
+ tbo = tb + " " + " "+ str(sl)
7
+ num = sl
8
+ print(tb + " " + " "+ str(sl))
9
+ cb = ['usa', 'japan', ]
10
+ if sl > 50:
11
+ raise gr.Error("This is not allowed!!!!!!!")
12
+ return tbo, num, cb
13
+
14
+ with demo:
15
+ tb = gr.Textbox()
16
+ sl = gr.Slider(minimum=1, maximum=100, step=5, info="hhe hhah kki ko")
17
+ b1 = gr.Button('button')
18
+ tbo = gr.Textbox()
19
+ num = gr.Number()
20
+ cb = gr.CheckboxGroup(label = "countries", choices= ["india", "usa", "japan"], value="usa")
21
+ b1.click(dummy, [tb, sl], [tbo, num, cb] )
22
+
23
+ examples = gr.Examples([["dd", 1], ["ggg", 4], ["kjkjk", 6]],
24
+ [tb, sl],
25
+ [tbo, num, cb],
26
+ dummy, cache_examples=True)
27
 
28
  demo.launch()