Update share link copy for HF Spaces compatibility.
Browse files- app.py +2 -2
- templates.py +6 -3
app.py
CHANGED
@@ -86,7 +86,7 @@ def transcribe(audio: str) -> (str, str):
|
|
86 |
return result["text"], None
|
87 |
|
88 |
|
89 |
-
def link_copy_notify():
|
90 |
gr.Info("Share link copied!")
|
91 |
|
92 |
|
@@ -147,7 +147,7 @@ with gr.Blocks() as demo:
|
|
147 |
with gr.Column():
|
148 |
gr.Markdown("## 3. Export your app to share!")
|
149 |
share_link_btn = gr.Button("π Copy share link to clipboard")
|
150 |
-
share_link_btn.click(link_copy_notify,
|
151 |
copy_snippet_btn = gr.Button("βοΈ Copy app snippet to paste into another page")
|
152 |
copy_snippet_btn.click(copy_notify, [gradio_code_area, gradio_requirements_area], None, _js=copy_snippet_js(DemoType.GRADIO))
|
153 |
download_btn = gr.Button("π Download app as a standalone file")
|
|
|
86 |
return result["text"], None
|
87 |
|
88 |
|
89 |
+
def link_copy_notify(code: str, requirements: str):
|
90 |
gr.Info("Share link copied!")
|
91 |
|
92 |
|
|
|
147 |
with gr.Column():
|
148 |
gr.Markdown("## 3. Export your app to share!")
|
149 |
share_link_btn = gr.Button("π Copy share link to clipboard")
|
150 |
+
share_link_btn.click(link_copy_notify, [gradio_code_area, gradio_requirements_area], None, _js=copy_share_link_js(DemoType.GRADIO))
|
151 |
copy_snippet_btn = gr.Button("βοΈ Copy app snippet to paste into another page")
|
152 |
copy_snippet_btn.click(copy_notify, [gradio_code_area, gradio_requirements_area], None, _js=copy_snippet_js(DemoType.GRADIO))
|
153 |
download_btn = gr.Button("π Download app as a standalone file")
|
templates.py
CHANGED
@@ -172,9 +172,12 @@ def update_iframe_js(demo_type: DemoType) -> str:
|
|
172 |
|
173 |
def copy_share_link_js(demo_type: DemoType) -> str:
|
174 |
if demo_type == DemoType.GRADIO:
|
175 |
-
return f"""async () => {{
|
176 |
-
const
|
177 |
-
|
|
|
|
|
|
|
178 |
}}"""
|
179 |
raise NotImplementedError(f'{demo_type} is not a supported demo type')
|
180 |
|
|
|
172 |
|
173 |
def copy_share_link_js(demo_type: DemoType) -> str:
|
174 |
if demo_type == DemoType.GRADIO:
|
175 |
+
return f"""async (code, requirements) => {{
|
176 |
+
const url = new URL(window.location.href);
|
177 |
+
url.searchParams.set('requirements', requirements);
|
178 |
+
url.searchParams.set('code', code);
|
179 |
+
await navigator.clipboard.writeText(url);
|
180 |
+
return [code, requirements]
|
181 |
}}"""
|
182 |
raise NotImplementedError(f'{demo_type} is not a supported demo type')
|
183 |
|