IM_not commited on
Commit
73a983a
·
1 Parent(s): 758b1a1

share=True

Browse files
Files changed (2) hide show
  1. app.py +29 -4
  2. sandbox.py +35 -0
app.py CHANGED
@@ -1,7 +1,32 @@
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!!"
 
 
 
 
 
 
 
 
 
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch(share=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()
sandbox.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+
4
+ # ################
5
+ # #example 1
6
+ # ################
7
+ #
8
+ # import gradio as gr
9
+ # def greet(name):
10
+ # return "Hello " + name + "!"
11
+ #
12
+ # demo = gr.Interface(
13
+ # fn=greet,
14
+ # inputs=gr.Textbox(lines=2, placeholder="Name Here..."),
15
+ # outputs="text",
16
+ # )
17
+ # demo.launch()
18
+ #
19
+ # ################
20
+ # #example 2
21
+ # ################
22
+
23
+ # import gradio as gr
24
+ # def greet(name, is_morning, temperature):
25
+ # salutation = "Good morning" if is_morning else "Good evening"
26
+ # greeting = f"{salutation} {name}. It is {temperature} degrees today"
27
+ # celsius = (temperature - 32) * 5 / 9
28
+ # return greeting, round(celsius, 2)
29
+ #
30
+ # demo = gr.Interface(
31
+ # fn=greet,
32
+ # inputs=["text", "checkbox", gr.Slider(0, 100)],
33
+ # outputs=["text", "number"],
34
+ # )
35
+ # demo.launch()