Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,37 @@
|
|
1 |
import gradio as gr
|
2 |
-
import random
|
3 |
-
import time
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
def textbox_dynamic(example: str):
|
7 |
-
yield gr.Textbox(placeholder="What is 2+2?")
|
8 |
-
time.sleep(1)
|
9 |
-
yield gr.Textbox(placeholder="What is the meaning of Life?")
|
10 |
-
time.sleep(1)
|
11 |
-
yield gr.Textbox(placeholder="What is Gradio?")
|
12 |
-
time.sleep(1)
|
13 |
-
|
14 |
with gr.Blocks() as demo:
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
msg.blur(textbox_dynamic, inputs=[msg], outputs=[msg], js=True, preprocess=False, postprocess=False)
|
29 |
-
|
30 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
+
def calculator(num1: int, operation: str, num2: int):
|
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 |
+
return num1 / num2
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
with gr.Blocks() as demo:
|
14 |
+
with gr.Row():
|
15 |
+
with gr.Column():
|
16 |
+
num_1 = gr.Number(value=4)
|
17 |
+
operation = gr.Radio(["add", "subtract", "multiply", "divide"])
|
18 |
+
num_2 = gr.Number(value=0)
|
19 |
+
submit_btn = gr.Button(value="Calculate")
|
20 |
+
with gr.Column():
|
21 |
+
result = gr.Number()
|
22 |
|
23 |
+
submit_btn.click(
|
24 |
+
calculator, inputs=[num_1, operation, num_2], outputs=[result], js=True, preprocess=False, postprocess=False
|
25 |
+
)
|
26 |
+
examples = gr.Examples(
|
27 |
+
examples=[
|
28 |
+
[5, "add", 3],
|
29 |
+
[4, "divide", 2],
|
30 |
+
[-4, "multiply", 2.5],
|
31 |
+
[0, "subtract", 1.2],
|
32 |
+
],
|
33 |
+
inputs=[num_1, operation, num_2],
|
34 |
+
)
|
35 |
|
36 |
+
if __name__ == "__main__":
|
37 |
+
demo.launch()
|
|
|
|
|
|