-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow building multipage Gradio apps (#10433)
* changes * add changeset * changes * chnages * changes * changes * add changeset * Update gradio/blocks.py Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update gradio/blocks.py Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * changes * changes * changes * chagnes * Update js/core/src/Blocks.svelte Co-authored-by: Hannah <hannahblair@users.noreply.github.com> * Update js/core/src/Blocks.svelte Co-authored-by: Hannah <hannahblair@users.noreply.github.com> * changes * chagnes * changes * changes * changes * changes * changes * changes * changes * docs * changes * changes * changes * rename guide * rename guide * changes * chagnes * add changeset * changes * changes * changes * changes * changes * changes * changes * changes * changes * add changeset * try skipping * format --------- Co-authored-by: Ali Abid <aliabid94@gmail.com> Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com> Co-authored-by: Abubakar Abid <abubakar@huggingface.co> Co-authored-by: Hannah <hannahblair@users.noreply.github.com>
- Loading branch information
1 parent
35fda36
commit 2e8dc74
Showing
21 changed files
with
510 additions
and
118 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,10 @@ | ||
--- | ||
"@gradio/client": minor | ||
"@gradio/core": minor | ||
"@gradio/lite": minor | ||
"@self/app": minor | ||
"@self/spa": minor | ||
"gradio": minor | ||
--- | ||
|
||
feat:Allow building multipage Gradio apps |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: multipage"]}, {"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", "import random\n", "import time\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", " @gr.on([greet_btn.click, name.submit], inputs=name, outputs=output)\n", " def greet(name):\n", " return \"Hello \" + name + \"!\"\n", " \n", " @gr.render(inputs=name, triggers=[output.change])\n", " def spell_out(name):\n", " with gr.Row():\n", " for letter in name:\n", " gr.Textbox(letter)\n", "\n", "with demo.route(\"Up\") as incrementer_demo:\n", " num = gr.Number()\n", " incrementer_demo.load(lambda: time.sleep(1) or random.randint(10, 40), None, num)\n", "\n", " with gr.Row():\n", " inc_btn = gr.Button(\"Increase\")\n", " dec_btn = gr.Button(\"Decrease\")\n", " inc_btn.click(fn=lambda x: x + 1, inputs=num, outputs=num, api_name=\"increment\")\n", " dec_btn.click(fn=lambda x: x - 1, inputs=num, outputs=num, api_name=\"decrement\")\n", " for i in range(100):\n", " gr.Textbox()\n", "\n", "def wait(x):\n", " time.sleep(2)\n", " return x\n", "\n", "identity_iface = gr.Interface(wait, \"image\", \"image\")\n", "\n", "with demo.route(\"Interface\") as incrementer_demo:\n", " identity_iface.render()\n", " gr.Interface(lambda x, y: x * y, [\"number\", \"number\"], \"number\")\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "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,42 @@ | ||
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") | ||
|
||
with demo.route("Interface") as incrementer_demo: | ||
identity_iface.render() | ||
gr.Interface(lambda x, y: x * y, ["number", "number"], "number") | ||
|
||
if __name__ == "__main__": | ||
demo.launch() |
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
Oops, something went wrong.