Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import random
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
+
with gr.Blocks() as demo:
|
| 6 |
+
name = gr.Textbox(label="Name")
|
| 7 |
+
output = gr.Textbox(label="Output Box")
|
| 8 |
+
greet_btn = gr.Button("Greet")
|
| 9 |
+
@gr.on([greet_btn.click, name.submit], inputs=name, outputs=output)
|
| 10 |
+
def greet(name):
|
| 11 |
+
return "Hello " + name + "!"
|
| 12 |
+
|
| 13 |
+
@gr.render(inputs=name, triggers=[output.change])
|
| 14 |
+
def spell_out(name):
|
| 15 |
+
with gr.Row():
|
| 16 |
+
for letter in name:
|
| 17 |
+
gr.Textbox(letter)
|
| 18 |
+
|
| 19 |
+
with demo.route("Up") as incrementer_demo:
|
| 20 |
+
num = gr.Number()
|
| 21 |
+
incrementer_demo.load(lambda: time.sleep(1) or random.randint(10, 40), None, num)
|
| 22 |
+
|
| 23 |
+
with gr.Row():
|
| 24 |
+
inc_btn = gr.Button("Increase")
|
| 25 |
+
dec_btn = gr.Button("Decrease")
|
| 26 |
+
inc_btn.click(fn=lambda x: x + 1, inputs=num, outputs=num, api_name="increment")
|
| 27 |
+
dec_btn.click(fn=lambda x: x - 1, inputs=num, outputs=num, api_name="decrement")
|
| 28 |
+
for i in range(100):
|
| 29 |
+
gr.Textbox()
|
| 30 |
+
|
| 31 |
+
def wait(x):
|
| 32 |
+
time.sleep(2)
|
| 33 |
+
return x
|
| 34 |
+
|
| 35 |
+
identity_iface = gr.Interface(wait, "image", "image")
|
| 36 |
+
|
| 37 |
+
with demo.route("Interface") as incrementer_demo:
|
| 38 |
+
identity_iface.render()
|
| 39 |
+
gr.Interface(lambda x, y: x * y, ["number", "number"], "number")
|
| 40 |
+
|
| 41 |
+
demo.launch()
|