Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import random
|
3 |
+
|
4 |
+
with gr.Blocks() as demo:
|
5 |
+
name = gr.Textbox(label="Name")
|
6 |
+
output = gr.Textbox(label="Output Box")
|
7 |
+
greet_btn = gr.Button("Greet")
|
8 |
+
@gr.on([greet_btn.click, name.submit], inputs=name, outputs=output, api_name="greet")
|
9 |
+
def greet(name):
|
10 |
+
return "Hello " + name + "!"
|
11 |
+
|
12 |
+
with demo.route("Up") as incrementer_demo:
|
13 |
+
num = gr.Number()
|
14 |
+
incrementer_demo.load(lambda: random.randint(10, 40), None, num)
|
15 |
+
|
16 |
+
with gr.Row():
|
17 |
+
inc_btn = gr.Button("Increase")
|
18 |
+
dec_btn = gr.Button("Decrease")
|
19 |
+
inc_btn.click(fn=lambda x: x + 1, inputs=num, outputs=num, api_name="increment")
|
20 |
+
dec_btn.click(fn=lambda x: x - 1, inputs=num, outputs=num, api_name="decrement")
|
21 |
+
|
22 |
+
if __name__ == "__main__":
|
23 |
+
demo.launch(ssr_mode=True)
|