Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -73,35 +73,57 @@ def img_tag(path: Path, alt: str, cls: str) -> str:
|
|
| 73 |
def inject_background(image_path: Path, opacity: float = 0.12) -> None:
|
| 74 |
"""
|
| 75 |
Paint a page-wide background image with adjustable opacity.
|
| 76 |
-
|
| 77 |
"""
|
| 78 |
uri = data_uri(image_path)
|
| 79 |
if not uri:
|
|
|
|
|
|
|
| 80 |
return
|
| 81 |
-
|
| 82 |
st.markdown(f"""
|
| 83 |
<style>
|
| 84 |
:root {{
|
| 85 |
--bg-opacity: {max(0.0, min(opacity, 1.0))};
|
| 86 |
}}
|
| 87 |
-
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
content: "";
|
| 90 |
-
position: fixed;
|
| 91 |
inset: 0;
|
| 92 |
-
z-index:
|
| 93 |
background-image: url('{uri}');
|
| 94 |
background-size: cover;
|
| 95 |
background-position: center;
|
| 96 |
background-repeat: no-repeat;
|
| 97 |
opacity: var(--bg-opacity);
|
| 98 |
-
filter: saturate(0.9) brightness(1.05);
|
|
|
|
| 99 |
}}
|
| 100 |
|
| 101 |
-
/*
|
| 102 |
-
|
| 103 |
-
background: transparent !important;
|
| 104 |
-
}}
|
| 105 |
</style>
|
| 106 |
""", unsafe_allow_html=True)
|
| 107 |
|
|
|
|
| 73 |
def inject_background(image_path: Path, opacity: float = 0.12) -> None:
|
| 74 |
"""
|
| 75 |
Paint a page-wide background image with adjustable opacity.
|
| 76 |
+
Works across Streamlit versions by targeting .stApp and the view container.
|
| 77 |
"""
|
| 78 |
uri = data_uri(image_path)
|
| 79 |
if not uri:
|
| 80 |
+
# Optional: small on-screen hint to confirm path issues
|
| 81 |
+
st.caption(f"Background image not found: {image_path}")
|
| 82 |
return
|
| 83 |
+
|
| 84 |
st.markdown(f"""
|
| 85 |
<style>
|
| 86 |
:root {{
|
| 87 |
--bg-opacity: {max(0.0, min(opacity, 1.0))};
|
| 88 |
}}
|
| 89 |
+
|
| 90 |
+
/* Make sure the app root can host a positioned overlay */
|
| 91 |
+
.stApp {{
|
| 92 |
+
position: relative !important;
|
| 93 |
+
background: transparent !important;
|
| 94 |
+
}}
|
| 95 |
+
|
| 96 |
+
/* Some Streamlit builds still use this container; keep it transparent */
|
| 97 |
+
[data-testid="stAppViewContainer"] {{
|
| 98 |
+
background: transparent !important;
|
| 99 |
+
}}
|
| 100 |
+
|
| 101 |
+
/* Main content area should not paint over the background */
|
| 102 |
+
[data-testid="stAppViewContainer"] > .main {{
|
| 103 |
+
background: transparent !important;
|
| 104 |
+
}}
|
| 105 |
+
|
| 106 |
+
html, body {{
|
| 107 |
+
background: transparent !important;
|
| 108 |
+
}}
|
| 109 |
+
|
| 110 |
+
/* Background overlay inside .stApp so it always sits behind content */
|
| 111 |
+
.stApp::before {{
|
| 112 |
content: "";
|
| 113 |
+
position: fixed; /* fixed to viewport */
|
| 114 |
inset: 0;
|
| 115 |
+
z-index: 0; /* below all content we'll raise to 1 */
|
| 116 |
background-image: url('{uri}');
|
| 117 |
background-size: cover;
|
| 118 |
background-position: center;
|
| 119 |
background-repeat: no-repeat;
|
| 120 |
opacity: var(--bg-opacity);
|
| 121 |
+
filter: saturate(0.9) brightness(1.05); /* add blur(2px) if desired */
|
| 122 |
+
pointer-events: none; /* never intercept clicks */
|
| 123 |
}}
|
| 124 |
|
| 125 |
+
/* Ensure all Streamlit content stacks above the bg */
|
| 126 |
+
.stApp > * {{ position: relative; z-index: 1; }}
|
|
|
|
|
|
|
| 127 |
</style>
|
| 128 |
""", unsafe_allow_html=True)
|
| 129 |
|