OzzyGT HF Staff commited on
Commit
4daa2b6
·
1 Parent(s): 860902e

final fix

Browse files
Files changed (1) hide show
  1. app.py +12 -14
app.py CHANGED
@@ -1508,23 +1508,21 @@ CANVAS_JS = r"""
1508
  # --app-h is a *fixed pixel* stand-in for 100vh. On HF Spaces the app runs in a <gradio-app>
1509
  # iframe that resizes to its content, so `vh` units feed back and grow forever. Pinning a pixel
1510
  # height from window.innerHeight (updated only on real resize) breaks that loop.
 
 
 
 
 
1511
  HEIGHT_SYNC_JS = (
1512
- "(function(){var h=0,dbg=null;"
1513
- "function s(){"
1514
- "var el=document.querySelector('.gradio-container');"
1515
- "var top=el?el.getBoundingClientRect().top:0;" # space taken by HF/host header above the app
1516
  "var a=Math.max(320, window.innerHeight - Math.max(0, top));"
1517
- "if(!h||a<h)h=a;" # only ever shrink: an auto-sizing embed can't make us run away
1518
- "document.documentElement.style.setProperty('--app-h', h + 'px');"
1519
- "try{if(!dbg&&document.body){dbg=document.createElement('div');"
1520
- "dbg.style.cssText='position:fixed;left:2px;bottom:2px;z-index:99999;background:#000;"
1521
- "color:#0f0;font:10px monospace;padding:2px 5px;opacity:.85;pointer-events:none';"
1522
- "document.body.appendChild(dbg);}"
1523
- "if(dbg)dbg.textContent='ih='+window.innerHeight+' top='+Math.round(top)+' appH='+h"
1524
- "+' bsh='+document.body.scrollHeight+' iframe='+(window.top!==window.self)+' gc='+(!!el);"
1525
- "}catch(e){}}"
1526
  "s();window.addEventListener('resize', s);window.addEventListener('load', s);"
1527
- "setTimeout(s,300);setTimeout(s,900);setTimeout(s,2000);})();"
1528
  )
1529
  HEAD = (
1530
  "<style>\n" + CSS + "\n</style>\n"
 
1508
  # --app-h is a *fixed pixel* stand-in for 100vh. On HF Spaces the app runs in a <gradio-app>
1509
  # iframe that resizes to its content, so `vh` units feed back and grow forever. Pinning a pixel
1510
  # height from window.innerHeight (updated only on real resize) breaks that loop.
1511
+ # --app-h is a fixed-px stand-in for the app height.
1512
+ # Direct URL (top-level page): use the real available viewport -> full-height, scrollless.
1513
+ # Embedded in an iframe (e.g. the HF Space page): the iframe is content-sized, so innerHeight is
1514
+ # circular and unrelated to the visible area — we can't know it, so we use a sensible fixed height.
1515
+ EMBED_HEIGHT_PX = 720
1516
  HEIGHT_SYNC_JS = (
1517
+ "(function(){var embedded=window.top!==window.self;var h=0;function s(){"
1518
+ "if(embedded){h=" + str(EMBED_HEIGHT_PX) + ";}"
1519
+ "else{var el=document.querySelector('.gradio-container');"
1520
+ "var top=el?el.getBoundingClientRect().top:0;"
1521
  "var a=Math.max(320, window.innerHeight - Math.max(0, top));"
1522
+ "if(!h||a<h)h=a;}" # only ever shrink on the direct URL (never chase an auto-sizing parent)
1523
+ "document.documentElement.style.setProperty('--app-h', h + 'px');}"
 
 
 
 
 
 
 
1524
  "s();window.addEventListener('resize', s);window.addEventListener('load', s);"
1525
+ "setTimeout(s,300);setTimeout(s,900);})();"
1526
  )
1527
  HEAD = (
1528
  "<style>\n" + CSS + "\n</style>\n"