Skip to content

Commit 25a2f47

Browse files
Address comments
1 parent 9c788e7 commit 25a2f47

File tree

6 files changed

+28
-6
lines changed

6 files changed

+28
-6
lines changed

demo/deep_link/run.ipynb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: deep_link"]}, {"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", "\n", "def random_response(message, history):\n", " return random.choice([\"Hi!\", \"Hello!\", \"Greetings!\"])\n", "\n", "with gr.Blocks() as demo:\n", " gr.ChatInterface(\n", " random_response,\n", " title=\"Greeting Bot\",\n", " description=\"Ask anything and receive a nice greeting!\",\n", " )\n", " gr.DeepLinkButton()\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch(share=True)\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}

demo/deep_link/run.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import gradio as gr
2+
import random
3+
4+
def random_response(message, history):
5+
return random.choice(["Hi!", "Hello!", "Greetings!"])
6+
7+
with gr.Blocks() as demo:
8+
gr.ChatInterface(
9+
random_response,
10+
title="Greeting Bot",
11+
description="Ask anything and receive a nice greeting!",
12+
)
13+
gr.DeepLinkButton()
14+
15+
if __name__ == "__main__":
16+
demo.launch(share=True)

gradio/components/deep_link_button.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ def get_share_link(
107107
.then(data => {
108108
const currentUrl = new URL(window.location.href);
109109
const cleanData = data.replace(/^"|"$/g, '');
110-
currentUrl.searchParams.set('deep_link', cleanData);
110+
if (cleanData) {
111+
currentUrl.searchParams.set('deep_link', cleanData);
112+
}
111113
navigator.clipboard.writeText(currentUrl.toString());
112114
})
113115
.catch(error => {

gradio/interface.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def __init__(
145145
| None = None,
146146
time_limit: int | None = 30,
147147
stream_every: float = 0.5,
148-
deep_link: str | DeepLinkButton | None = None,
148+
deep_link: str | DeepLinkButton | bool | None = None,
149149
**kwargs,
150150
):
151151
"""
@@ -188,6 +188,7 @@ def __init__(
188188
fill_width: whether to horizontally expand to fill container fully. If False, centers and constrains app to a maximum width.
189189
time_limit: The time limit for the stream to run. Default is 30 seconds. Parameter only used for streaming images or audio if the interface is live and the input components are set to "streaming=True".
190190
stream_every: The latency (in seconds) at which stream chunks are sent to the backend. Defaults to 0.5 seconds. Parameter only used for streaming images or audio if the interface is live and the input components are set to "streaming=True".
191+
deep_link: a string or `gr.DeepLinkButton` object that creates a unique URL you can use to share your app and all components **as they currently are** with others. Automatically enabled on Hugging Face Spaces unless explicitly set to False.
191192
"""
192193
super().__init__(
193194
analytics_enabled=analytics_enabled,
@@ -205,9 +206,11 @@ def __init__(
205206
)
206207
if isinstance(deep_link, str):
207208
deep_link = DeepLinkButton(value=deep_link)
208-
if utils.get_space() and not deep_link:
209+
elif deep_link is True:
209210
deep_link = DeepLinkButton()
210-
if wasm_utils.IS_WASM:
211+
if utils.get_space() and deep_link is None:
212+
deep_link = DeepLinkButton()
213+
if wasm_utils.IS_WASM or deep_link is False:
211214
deep_link = None
212215
self.deep_link = deep_link
213216
self.time_limit = time_limit

gradio/routes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ def deep_link(session_hash: str):
661661
f.write(components_json)
662662
return deep_link
663663
else:
664-
return "Error"
664+
return ""
665665

666666
@router.get("/info/", dependencies=[Depends(login_check)])
667667
@router.get("/info", dependencies=[Depends(login_check)])

guides/04_additional-features/07_sharing-your-app.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ After you have [created a free Hugging Face account](https://huggingface.co/join
5656

5757
## Sharing Deep Links
5858

59-
You can add a button to your Gradio app that creates a unique URL you can use to share your app **as it currently is** with others. This is useful for sharing unique and interesting generations from your application , or for saving a snapshot of your app at a particular point in time.
59+
You can add a button to your Gradio app that creates a unique URL you can use to share your app and all components **as they currently are** with others. This is useful for sharing unique and interesting generations from your application , or for saving a snapshot of your app at a particular point in time.
6060

6161
To add a deep link button to your app, place the `gr.DeepLinkButton` component anywhere in your app.
6262
For the URL to be accessible to others, your app must be available at a public URL. So be sure to host your app like Hugging Face Spaces or use the `share=True` parameter when launching your app.

0 commit comments

Comments
 (0)