Update app.py
Browse files
app.py
CHANGED
|
@@ -781,10 +781,85 @@ html,body,.gradio-container{
|
|
| 781 |
.gr-textbox textarea[readonly]{ background:#111827 !important; color:#f9fafb !important; border:1px solid #374151 !important; }
|
| 782 |
.gr-dropdown,.gr-dropdown .gr-box{ background:#fff !important; border:1px solid var(--border) !important; border-radius:8px !important; }
|
| 783 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 784 |
|
| 785 |
with gr.Blocks(css=CSS, fill_height=True, title="Interactive Blog — Transformers Feature Showcase") as demo:
|
| 786 |
gr.HTML(HLJS)
|
| 787 |
-
|
| 788 |
with gr.Row(elem_id="layout-row"):
|
| 789 |
# This column holds the Table of Contents. It is fixed on desktop.
|
| 790 |
with gr.Column(scale=1, min_width=300, elem_id="toc-column"):
|
|
|
|
| 781 |
.gr-textbox textarea[readonly]{ background:#111827 !important; color:#f9fafb !important; border:1px solid #374151 !important; }
|
| 782 |
.gr-dropdown,.gr-dropdown .gr-box{ background:#fff !important; border:1px solid var(--border) !important; border-radius:8px !important; }
|
| 783 |
"""
|
| 784 |
+
TOC_FIX = """
|
| 785 |
+
<style>
|
| 786 |
+
/* --- Keep fixed elements from breaking inside Gradio containers --- */
|
| 787 |
+
.gradio-container{ overflow:visible !important; }
|
| 788 |
+
.gradio-container, .gradio-container > *{ transform:none !important; }
|
| 789 |
+
|
| 790 |
+
/* --- Host created by the script; this is the real fixed TOC --- */
|
| 791 |
+
#toc-fixed{
|
| 792 |
+
position:fixed; top:0; left:0;
|
| 793 |
+
height:100vh; width:320px; /* matches your --tocw */
|
| 794 |
+
z-index:9999; overflow-y:auto;
|
| 795 |
+
background:#fff; border-right:1px solid #e5e7eb;
|
| 796 |
+
padding:1rem; box-sizing:border-box;
|
| 797 |
+
}
|
| 798 |
+
|
| 799 |
+
/* When fixed mode is active, keep the original column's space but hide its content */
|
| 800 |
+
.toc-fixed-active #toc-column{ visibility:hidden; }
|
| 801 |
+
|
| 802 |
+
/* Mobile: disable fixed TOC (normal flow) */
|
| 803 |
+
@media (max-width: 899.98px){
|
| 804 |
+
#toc-fixed{ display:none; }
|
| 805 |
+
.toc-fixed-active #toc-column{ visibility:visible; }
|
| 806 |
+
}
|
| 807 |
+
</style>
|
| 808 |
+
|
| 809 |
+
<script>
|
| 810 |
+
(function(){
|
| 811 |
+
const MIN_W = 900; // desktop threshold
|
| 812 |
+
|
| 813 |
+
function mountFixedTOC(){
|
| 814 |
+
const col = document.getElementById('toc-column');
|
| 815 |
+
const nav = col && col.querySelector('nav#toc');
|
| 816 |
+
if(!col || !nav) return;
|
| 817 |
+
|
| 818 |
+
const isDesktop = window.innerWidth >= MIN_W;
|
| 819 |
+
let fixed = document.getElementById('toc-fixed');
|
| 820 |
+
|
| 821 |
+
if(isDesktop){
|
| 822 |
+
// create fixed host if missing
|
| 823 |
+
if(!fixed){
|
| 824 |
+
fixed = document.createElement('aside');
|
| 825 |
+
fixed.id = 'toc-fixed';
|
| 826 |
+
document.body.appendChild(fixed);
|
| 827 |
+
}
|
| 828 |
+
// move the nav into the fixed host
|
| 829 |
+
if(nav.parentElement !== fixed){
|
| 830 |
+
fixed.innerHTML = '';
|
| 831 |
+
fixed.appendChild(nav);
|
| 832 |
+
}
|
| 833 |
+
// align the fixed TOC with the placeholder column
|
| 834 |
+
const rect = col.getBoundingClientRect();
|
| 835 |
+
fixed.style.left = (rect.left + window.scrollX) + 'px';
|
| 836 |
+
fixed.style.width = getComputedStyle(col).width;
|
| 837 |
+
|
| 838 |
+
document.documentElement.classList.add('toc-fixed-active');
|
| 839 |
+
}else{
|
| 840 |
+
// mobile: put nav back into the original column
|
| 841 |
+
if(fixed && nav.parentElement === fixed){
|
| 842 |
+
col.appendChild(nav);
|
| 843 |
+
}
|
| 844 |
+
document.documentElement.classList.remove('toc-fixed-active');
|
| 845 |
+
}
|
| 846 |
+
}
|
| 847 |
+
|
| 848 |
+
// Run on load, after hydration, on resize, and when layout shifts
|
| 849 |
+
document.addEventListener('DOMContentLoaded', mountFixedTOC);
|
| 850 |
+
window.addEventListener('resize', mountFixedTOC);
|
| 851 |
+
setTimeout(mountFixedTOC, 300);
|
| 852 |
+
|
| 853 |
+
const target = document.querySelector('.gradio-container') || document.body;
|
| 854 |
+
new ResizeObserver(mountFixedTOC).observe(target);
|
| 855 |
+
})();
|
| 856 |
+
</script>
|
| 857 |
+
"""
|
| 858 |
+
|
| 859 |
|
| 860 |
with gr.Blocks(css=CSS, fill_height=True, title="Interactive Blog — Transformers Feature Showcase") as demo:
|
| 861 |
gr.HTML(HLJS)
|
| 862 |
+
gr.HTML(TOC_FIX)
|
| 863 |
with gr.Row(elem_id="layout-row"):
|
| 864 |
# This column holds the Table of Contents. It is fixed on desktop.
|
| 865 |
with gr.Column(scale=1, min_width=300, elem_id="toc-column"):
|