Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce decorator syntax for event listeners (#5395)
* changes * add changeset * changes * changes * Update fuzzy-numbers-repair.md * Update fuzzy-numbers-repair.md --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
- Loading branch information
1 parent
abf1c57
commit 55fed04
Showing
7 changed files
with
79 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
"gradio": minor | ||
--- | ||
|
||
highlight: | ||
|
||
#### Added the ability to attach event listeners via decorators | ||
|
||
e.g. | ||
|
||
```python | ||
with gr.Blocks() as demo: | ||
name = gr.Textbox(label="Name") | ||
output = gr.Textbox(label="Output Box") | ||
greet_btn = gr.Button("Greet") | ||
|
||
@greet_btn.click(inputs=name, outputs=output) | ||
def greet(name): | ||
return "Hello " + name + "!" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"cells": [{"cell_type": "markdown", "id": 302934307671667531413257853548643485645, "metadata": {}, "source": ["# Gradio Demo: hello_blocks_decorator"]}, {"cell_type": "code", "execution_count": null, "id": 272996653310673477252411125948039410165, "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": 288918539441861185822528903084949547379, "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "\n", "\n", "with gr.Blocks() as demo:\n", " name = gr.Textbox(label=\"Name\")\n", " output = gr.Textbox(label=\"Output Box\")\n", " greet_btn = gr.Button(\"Greet\")\n", "\n", " @greet_btn.click(inputs=name, outputs=output)\n", " def greet(name):\n", " return \"Hello \" + name + \"!\"\n", "\n", " \n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import gradio as gr | ||
|
||
|
||
with gr.Blocks() as demo: | ||
name = gr.Textbox(label="Name") | ||
output = gr.Textbox(label="Output Box") | ||
greet_btn = gr.Button("Greet") | ||
|
||
@greet_btn.click(inputs=name, outputs=output) | ||
def greet(name): | ||
return "Hello " + name + "!" | ||
|
||
|
||
|
||
if __name__ == "__main__": | ||
demo.launch() |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters