Anton Obukhov commited on
Commit
21346a4
·
unverified ·
1 Parent(s): 559a8ac

iframe embedding control (#2)

Browse files

external signal to hide some elements when embedding on a parent website

Files changed (2) hide show
  1. app.py +19 -14
  2. gradio_dualvision/app_template.py +19 -0
app.py CHANGED
@@ -21,21 +21,26 @@ 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">
27
- </a>
28
- <a title="Social" href="https://twitter.com/antonobukhov1" target="_blank" rel="noopener noreferrer" style="display: inline-block;">
29
- <img src="https://shields.io/twitter/follow/:?label=Subscribe%20for%20updates!" alt="social">
30
- </a>
31
- </p>
32
- <p align="center" style="margin-top: 0px;">
33
- Upload a photo or select an example to process the input in real time.
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):
41
  """
 
21
  gr.Markdown(
22
  f"""
23
  ## {self.title}
24
+ """
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  )
26
+ with gr.Row(elem_classes="remove-elements"):
27
+ gr.Markdown(
28
+ f"""
29
+ <p align="center">
30
+ <a title="Github" href="https://github.com/toshas/gradio-dualvision" target="_blank" rel="noopener noreferrer" style="display: inline-block;">
31
+ <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">
32
+ </a>
33
+ <a title="Social" href="https://twitter.com/antonobukhov1" target="_blank" rel="noopener noreferrer" style="display: inline-block;">
34
+ <img src="https://shields.io/twitter/follow/:?label=Subscribe%20for%20updates!" alt="social">
35
+ </a>
36
+ </p>
37
+ <p align="center" style="margin-top: 0px;">
38
+ Upload a photo or select an example to process the input in real time.
39
+ Use the slider to reveal areas of interest.
40
+ Use the radio-buttons to switch between modalities.
41
+ </p>
42
+ """
43
+ )
44
 
45
  def build_user_components(self):
46
  """
gradio_dualvision/app_template.py CHANGED
@@ -110,6 +110,25 @@ class DualVisionApp(gr.Blocks):
110
  )
111
  self.head = ""
112
  self.head += """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  <script>
114
  let observerFooterButtons = new MutationObserver((mutationsList, observer) => {
115
  const oldButtonLeft = document.querySelector(".show-api");
 
110
  )
111
  self.head = ""
112
  self.head += """
113
+ <script>
114
+ window.addEventListener("message", (event) => {
115
+ if (event.data?.type === "remove-elements") {
116
+ const removeTargets = () => {
117
+ const targets = document.querySelectorAll(".remove-elements");
118
+ targets.forEach(el => el.remove());
119
+ };
120
+
121
+ removeTargets();
122
+ const observer = new MutationObserver(() => {
123
+ removeTargets();
124
+ });
125
+ observer.observe(document.body, { childList: true, subtree: true });
126
+
127
+ event.source?.postMessage({ type: "ack-remove-elements", source: "gradio-app" }, event.origin);
128
+ console.log("Processed event remove-elements");
129
+ }
130
+ });
131
+ </script>
132
  <script>
133
  let observerFooterButtons = new MutationObserver((mutationsList, observer) => {
134
  const oldButtonLeft = document.querySelector(".show-api");