Update app.py
Browse files
app.py
CHANGED
@@ -1,68 +1,142 @@
|
|
1 |
import streamlit as st
|
2 |
|
3 |
# ---- HEADER CONFIGURATION ----
|
4 |
-
# More
|
5 |
custom_css = """
|
6 |
<style>
|
7 |
/* Target the header with multiple selectors for better compatibility */
|
8 |
header[data-testid="stHeader"],
|
9 |
-
.stApp > header
|
|
|
10 |
position: fixed !important;
|
11 |
top: 0 !important;
|
12 |
left: 0 !important;
|
13 |
right: 0 !important;
|
14 |
-
width:
|
15 |
z-index: 999999 !important;
|
16 |
background-color: #90EE90 !important;
|
17 |
box-shadow: 0 1px 5px rgba(0,0,0,0.1) !important;
|
|
|
18 |
}
|
19 |
|
20 |
/* Adjust main content to prevent overlap with fixed header */
|
21 |
section[data-testid="stMain"],
|
22 |
-
.main .block-container
|
23 |
-
|
|
|
24 |
margin-top: 10px !important;
|
25 |
}
|
26 |
|
27 |
-
/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
.st-emotion-cache-lrlib {
|
29 |
padding-top: 60px !important;
|
30 |
}
|
31 |
|
32 |
-
/*
|
33 |
-
|
34 |
-
|
35 |
}
|
36 |
|
37 |
-
/*
|
38 |
body.hf-w-body .stApp {
|
39 |
-
padding-top:
|
|
|
|
|
|
|
|
|
|
|
40 |
}
|
41 |
</style>
|
42 |
"""
|
43 |
|
44 |
-
#
|
45 |
js_fix = """
|
46 |
<script>
|
47 |
-
// This script
|
48 |
window.addEventListener('DOMContentLoaded', (event) => {
|
49 |
-
//
|
50 |
-
|
|
|
51 |
const header = document.querySelector('header[data-testid="stHeader"]');
|
52 |
if (header) {
|
|
|
53 |
header.style.position = 'fixed';
|
54 |
header.style.top = '0';
|
55 |
header.style.zIndex = '999999';
|
56 |
header.style.width = '100%';
|
57 |
header.style.backgroundColor = '#90EE90';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
-
//
|
60 |
-
|
61 |
-
if (
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
63 |
}
|
64 |
}
|
65 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
});
|
67 |
</script>
|
68 |
"""
|
|
|
1 |
import streamlit as st
|
2 |
|
3 |
# ---- HEADER CONFIGURATION ----
|
4 |
+
# More comprehensive CSS to handle both inner and outer scrollbars
|
5 |
custom_css = """
|
6 |
<style>
|
7 |
/* Target the header with multiple selectors for better compatibility */
|
8 |
header[data-testid="stHeader"],
|
9 |
+
.stApp > header,
|
10 |
+
div[data-testid="stAppViewBlockContainer"] > header {
|
11 |
position: fixed !important;
|
12 |
top: 0 !important;
|
13 |
left: 0 !important;
|
14 |
right: 0 !important;
|
15 |
+
width: 100vw !important;
|
16 |
z-index: 999999 !important;
|
17 |
background-color: #90EE90 !important;
|
18 |
box-shadow: 0 1px 5px rgba(0,0,0,0.1) !important;
|
19 |
+
min-height: 60px !important;
|
20 |
}
|
21 |
|
22 |
/* Adjust main content to prevent overlap with fixed header */
|
23 |
section[data-testid="stMain"],
|
24 |
+
.main .block-container,
|
25 |
+
div[data-testid="stDecoratedAppViewContainer"] div[data-testid="stAppViewContainer"] {
|
26 |
+
padding-top: 70px !important; /* Match your header height + some extra space */
|
27 |
margin-top: 10px !important;
|
28 |
}
|
29 |
|
30 |
+
/* Target the root element in Hugging Face environment */
|
31 |
+
#root {
|
32 |
+
position: relative !important;
|
33 |
+
}
|
34 |
+
|
35 |
+
/* Make the iframe itself handle scrolling properly */
|
36 |
+
#streamlit-iframe {
|
37 |
+
overflow: auto !important;
|
38 |
+
height: 100vh !important;
|
39 |
+
}
|
40 |
+
|
41 |
+
/* Handle outer scrollbar scenario */
|
42 |
+
body {
|
43 |
+
overflow: auto !important;
|
44 |
+
}
|
45 |
+
|
46 |
+
/* Target both inner and outer scroll containers */
|
47 |
+
.stApp,
|
48 |
+
div[data-testid="stAppViewBlockContainer"],
|
49 |
+
div.streamlit-container,
|
50 |
+
div[data-testid="stDecoratedAppViewContainer"] {
|
51 |
+
position: relative !important;
|
52 |
+
padding-top: 0 !important;
|
53 |
+
}
|
54 |
+
|
55 |
+
/* Fix for Hugging Face specific container */
|
56 |
.st-emotion-cache-lrlib {
|
57 |
padding-top: 60px !important;
|
58 |
}
|
59 |
|
60 |
+
/* Handle any custom scrollable containers */
|
61 |
+
div.streamlit-container {
|
62 |
+
overflow: visible !important;
|
63 |
}
|
64 |
|
65 |
+
/* Ensure header remains visible with outside scrollbar */
|
66 |
body.hf-w-body .stApp {
|
67 |
+
padding-top: 0 !important;
|
68 |
+
}
|
69 |
+
|
70 |
+
/* Target Hugging Face's specific elements */
|
71 |
+
.gradient-border-wrap {
|
72 |
+
margin-top: 60px !important;
|
73 |
}
|
74 |
</style>
|
75 |
"""
|
76 |
|
77 |
+
# Enhanced JavaScript for complete handling of both scrollbar scenarios
|
78 |
js_fix = """
|
79 |
<script>
|
80 |
+
// This script ensures the header stays fixed in both scrollbar scenarios
|
81 |
window.addEventListener('DOMContentLoaded', (event) => {
|
82 |
+
// Function to apply header fixing
|
83 |
+
const fixHeader = () => {
|
84 |
+
// Target the header
|
85 |
const header = document.querySelector('header[data-testid="stHeader"]');
|
86 |
if (header) {
|
87 |
+
// Make it fixed
|
88 |
header.style.position = 'fixed';
|
89 |
header.style.top = '0';
|
90 |
header.style.zIndex = '999999';
|
91 |
header.style.width = '100%';
|
92 |
header.style.backgroundColor = '#90EE90';
|
93 |
+
header.style.minHeight = '60px';
|
94 |
+
|
95 |
+
// Add padding to main content (multiple selectors)
|
96 |
+
const mainContainers = [
|
97 |
+
document.querySelector('section[data-testid="stMain"]'),
|
98 |
+
document.querySelector('.main .block-container'),
|
99 |
+
document.querySelector('div[data-testid="stAppViewContainer"]'),
|
100 |
+
document.querySelector('div.streamlit-container')
|
101 |
+
];
|
102 |
+
|
103 |
+
mainContainers.forEach(container => {
|
104 |
+
if (container) {
|
105 |
+
container.style.paddingTop = '70px';
|
106 |
+
}
|
107 |
+
});
|
108 |
+
|
109 |
+
// Handle outer scrollbar - make sure header is visible
|
110 |
+
const outerScroll = () => {
|
111 |
+
const scrollY = window.scrollY || window.pageYOffset;
|
112 |
+
if (scrollY > 0) {
|
113 |
+
header.style.top = scrollY + 'px';
|
114 |
+
} else {
|
115 |
+
header.style.top = '0';
|
116 |
+
}
|
117 |
+
};
|
118 |
|
119 |
+
// Apply to both window and any iframe parent
|
120 |
+
window.addEventListener('scroll', outerScroll);
|
121 |
+
if (window.parent && window.parent !== window) {
|
122 |
+
try {
|
123 |
+
window.parent.addEventListener('scroll', outerScroll);
|
124 |
+
} catch (e) {
|
125 |
+
// Cross-origin issues might prevent this
|
126 |
+
console.log('Could not attach to parent scroll');
|
127 |
+
}
|
128 |
}
|
129 |
}
|
130 |
+
};
|
131 |
+
|
132 |
+
// Apply immediately
|
133 |
+
fixHeader();
|
134 |
+
|
135 |
+
// And again after a short delay to ensure all elements are loaded
|
136 |
+
setTimeout(fixHeader, 500);
|
137 |
+
|
138 |
+
// And one more time after everything is definitely loaded
|
139 |
+
setTimeout(fixHeader, 2000);
|
140 |
});
|
141 |
</script>
|
142 |
"""
|