gradio-app--gradio
adf0d17497
publish / version_or_publish (push) Has been cancelled
storybook-build / changes (push) Has been cancelled
storybook-build / :storybook-build (push) Has been cancelled
Sync Gradio Skills to Hugging Face / sync-skills (push) Has been cancelled
functional / changes (push) Has been cancelled
functional / build-frontend (push) Has been cancelled
functional / functional-test-SSR=false (push) Has been cancelled
functional / functional-reload (push) Has been cancelled
js / changes (push) Has been cancelled
js / js-test (push) Has been cancelled
docs-build / changes (push) Has been cancelled
docs-build / docs-build (push) Has been cancelled
docs-build / website-build (push) Has been cancelled
functional / functional-test-SSR=true (push) Has been cancelled
hygiene / hygiene-test (push) Has been cancelled
python / changes (push) Has been cancelled
python / build (push) Has been cancelled
python / test-ubuntu-latest-flaky (push) Has been cancelled
python / test-ubuntu-latest-not-flaky (push) Has been cancelled
python / test-windows-latest-flaky (push) Has been cancelled
python / test-windows-latest-not-flaky (push) Has been cancelled
43 行
1.3 KiB
Python
43 行
1.3 KiB
Python
import gradio as gr
|
|
import random
|
|
import time
|
|
|
|
with gr.Blocks() as demo:
|
|
name = gr.Textbox(label="Name")
|
|
output = gr.Textbox(label="Output Box")
|
|
greet_btn = gr.Button("Greet")
|
|
@gr.on([greet_btn.click, name.submit], inputs=name, outputs=output)
|
|
def greet(name):
|
|
return "Hello " + name + "!"
|
|
|
|
@gr.render(inputs=name, triggers=[output.change])
|
|
def spell_out(name):
|
|
with gr.Row():
|
|
for letter in name:
|
|
gr.Textbox(letter)
|
|
|
|
with demo.route("Up") as incrementer_demo:
|
|
num = gr.Number()
|
|
incrementer_demo.load(lambda: time.sleep(1) or random.randint(10, 40), None, num)
|
|
|
|
with gr.Row():
|
|
inc_btn = gr.Button("Increase")
|
|
dec_btn = gr.Button("Decrease")
|
|
inc_btn.click(fn=lambda x: x + 1, inputs=num, outputs=num, api_name="increment")
|
|
dec_btn.click(fn=lambda x: x - 1, inputs=num, outputs=num, api_name="decrement")
|
|
for i in range(100):
|
|
gr.Textbox()
|
|
|
|
def wait(x):
|
|
time.sleep(2)
|
|
return x
|
|
|
|
identity_iface = gr.Interface(wait, "image", "image", api_name="predict")
|
|
|
|
with demo.route("Interface") as incrementer_demo:
|
|
identity_iface.render()
|
|
gr.Interface(lambda x, y: x * y, ["number", "number"], "number", api_name="predict")
|
|
|
|
if __name__ == "__main__":
|
|
demo.launch()
|