Spaces:
Running
Running
implement markdown-verbose external signal to hide some elements when embedding on parent websites
Browse files- app.py +6 -1
- gradio_dualvision/app_template.py +13 -0
app.py
CHANGED
@@ -21,6 +21,10 @@ class ImageFiltersApp(DualVisionApp):
|
|
21 |
gr.Markdown(
|
22 |
f"""
|
23 |
## {self.title}
|
|
|
|
|
|
|
|
|
24 |
<p align="center">
|
25 |
<a title="Github" href="https://github.com/toshas/gradio-dualvision" target="_blank" rel="noopener noreferrer" style="display: inline-block;">
|
26 |
<img src="https://img.shields.io/github/stars/toshas/gradio-dualvision?label=GitHub%20%E2%98%85&logo=github&color=C8C" alt="badge-github-stars">
|
@@ -34,7 +38,8 @@ class ImageFiltersApp(DualVisionApp):
|
|
34 |
Use the slider to reveal areas of interest.
|
35 |
Use the radio-buttons to switch between modalities.
|
36 |
</p>
|
37 |
-
|
|
|
38 |
)
|
39 |
|
40 |
def build_user_components(self):
|
|
|
21 |
gr.Markdown(
|
22 |
f"""
|
23 |
## {self.title}
|
24 |
+
"""
|
25 |
+
)
|
26 |
+
gr.Markdown(
|
27 |
+
f"""
|
28 |
<p align="center">
|
29 |
<a title="Github" href="https://github.com/toshas/gradio-dualvision" target="_blank" rel="noopener noreferrer" style="display: inline-block;">
|
30 |
<img src="https://img.shields.io/github/stars/toshas/gradio-dualvision?label=GitHub%20%E2%98%85&logo=github&color=C8C" alt="badge-github-stars">
|
|
|
38 |
Use the slider to reveal areas of interest.
|
39 |
Use the radio-buttons to switch between modalities.
|
40 |
</p>
|
41 |
+
""",
|
42 |
+
elem_classes="markdown-verbose",
|
43 |
)
|
44 |
|
45 |
def build_user_components(self):
|
gradio_dualvision/app_template.py
CHANGED
@@ -148,7 +148,20 @@ class DualVisionApp(gr.Blocks):
|
|
148 |
});
|
149 |
observerFooterButtons.observe(document.body, { childList: true, subtree: true });
|
150 |
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
if kwargs.get("analytics_enabled") is not False:
|
153 |
self.head += f"""
|
154 |
<script async src="https://www.googletagmanager.com/gtag/js?id=G-1FWSVCGZTG"></script>
|
|
|
148 |
});
|
149 |
observerFooterButtons.observe(document.body, { childList: true, subtree: true });
|
150 |
</script>
|
151 |
+
<script>
|
152 |
+
window.addEventListener("message", (event) => {
|
153 |
+
if (event.data?.type === "markdown-verbose") {
|
154 |
+
document.querySelectorAll(".markdown-verbose").forEach(el => el.remove());
|
155 |
+
}
|
156 |
+
});
|
157 |
+
</script>
|
158 |
"""
|
159 |
+
# Invoke like this in the parent page:
|
160 |
+
# document.querySelectorAll("iframe").forEach((iframe) => {
|
161 |
+
# iframe.addEventListener("load", () => {
|
162 |
+
# iframe.contentWindow.postMessage({ type: "markdown-verbose" }, "*");
|
163 |
+
# });
|
164 |
+
# });
|
165 |
if kwargs.get("analytics_enabled") is not False:
|
166 |
self.head += f"""
|
167 |
<script async src="https://www.googletagmanager.com/gtag/js?id=G-1FWSVCGZTG"></script>
|