paulnovello-nk Claude Opus 5.5 commited on
Commit
14cd2c8
·
1 Parent(s): f821c9f

Open the upload dialog around its button

Browse files

On huggingface.co the app sits in an iframe as tall as the page, which the Hub's page
scrolls: a dialog centred on the iframe's viewport opened mid-page, often off screen.
It now opens around the "Upload my own CSV" button, where the visitor is looking,
kept within the viewport; the backdrop still covers the page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Files changed (2) hide show
  1. app.py +17 -0
  2. static/style.css +4 -3
app.py CHANGED
@@ -934,6 +934,18 @@ def palette(ink, panel, line, text, muted, focus):
934
 
935
  # Dark by default, whatever the viewer's system; light with ?__theme=light or the header's
936
  # toggle, whose last choice the browser remembers.
 
 
 
 
 
 
 
 
 
 
 
 
937
  THEME_JS = """
938
  () => {
939
  const KEY = "seldon-demo-theme";
@@ -1015,6 +1027,11 @@ with gr.Blocks(title="Seldon · Neuralk") as demo:
1015
 
1016
  results = [compare, confusions, predictions]
1017
  page = [preview, target, shape, test_size, seldon_card, autogluon_card, *results]
 
 
 
 
 
1018
  upload_button.click(open_upload, None, upload_modal, api_name=False, queue=False)
1019
  cancel_button.click(close_upload, None, [upload_modal, file], api_name=False, queue=False)
1020
  # An upload joins the list and is chosen, which changes the source and shows it.
 
934
 
935
  # Dark by default, whatever the viewer's system; light with ?__theme=light or the header's
936
  # toggle, whose last choice the browser remembers.
937
+ # Where the upload dialog's card opens: around the Upload button, which then sits near
938
+ # the card's middle, kept within the viewport (on huggingface.co, the whole page).
939
+ PLACE_UPLOAD_JS = """
940
+ () => {
941
+ const button = document.querySelector(".upload-open");
942
+ const top = button ? button.getBoundingClientRect().top - 200 : 80;
943
+ const room = window.innerHeight - 560; // the card is about 540 px tall
944
+ const y = Math.max(16, Math.min(top, room));
945
+ document.documentElement.style.setProperty("--upload-top", `${y}px`);
946
+ }
947
+ """
948
+
949
  THEME_JS = """
950
  () => {
951
  const KEY = "seldon-demo-theme";
 
1027
 
1028
  results = [compare, confusions, predictions]
1029
  page = [preview, target, shape, test_size, seldon_card, autogluon_card, *results]
1030
+ # The dialog opens level with the button, where the visitor is looking. On
1031
+ # huggingface.co the page sits in an iframe as tall as the page itself, which the
1032
+ # Hub's page scrolls: the iframe's viewport, which a centred dialog would centre on,
1033
+ # is the whole page, and its scroll is out of the page's reach.
1034
+ upload_button.click(None, None, None, js=PLACE_UPLOAD_JS)
1035
  upload_button.click(open_upload, None, upload_modal, api_name=False, queue=False)
1036
  cancel_button.click(close_upload, None, [upload_modal, file], api_name=False, queue=False)
1037
  # An upload joins the list and is chosen, which changes the source and shows it.
static/style.css CHANGED
@@ -541,10 +541,11 @@
541
  max-width: none !important;
542
  height: 100vh;
543
  margin: 0 !important;
544
- padding: 24px !important;
545
  display: flex;
546
- align-items: center;
547
- justify-content: center;
 
548
  background: rgba(8, 7, 14, 0.62) !important;
549
  backdrop-filter: blur(4px);
550
  }
 
541
  max-width: none !important;
542
  height: 100vh;
543
  margin: 0 !important;
544
+ padding: var(--upload-top, 15vh) 24px 24px !important; /* set on opening, by the button */
545
  display: flex;
546
+ flex-direction: column !important; /* a Gradio column: the card, from the top down */
547
+ justify-content: flex-start !important;
548
+ align-items: center !important;
549
  background: rgba(8, 7, 14, 0.62) !important;
550
  backdrop-filter: blur(4px);
551
  }