Commit ·
b4ec558
1
Parent(s): 3415cbd
Optimize: Sidebar sticky + fast image loading with cache
Browse files- pages/2_Projects.py +22 -16
- styles.css +9 -0
pages/2_Projects.py
CHANGED
|
@@ -1,29 +1,35 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from config import PROJECTS
|
| 3 |
import base64
|
|
|
|
| 4 |
|
| 5 |
st.set_page_config(page_title="Projets", page_icon="💼", layout="wide")
|
| 6 |
|
| 7 |
with open("styles.css", encoding="utf-8") as f:
|
| 8 |
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
for i in range(1, 5):
|
| 16 |
-
all_images.append(f"images/projects/dakar_{i}.png")
|
| 17 |
-
all_images.append(f"images/projects/tidianeflix_{i}.png")
|
| 18 |
-
all_images.append(f"images/projects/sentimentscope_{i}.png")
|
| 19 |
-
all_images.append(f"images/projects/climate_change{i}.png")
|
| 20 |
-
|
| 21 |
-
for img_path in all_images:
|
| 22 |
try:
|
| 23 |
with open(img_path, "rb") as f:
|
| 24 |
-
|
| 25 |
except:
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
html = '<h1 style="color: #00D9FF; text-align: center; margin-bottom: 3rem; font-weight: 800;">💼 Mes Projets Data Science</h1>'
|
| 29 |
|
|
@@ -49,9 +55,9 @@ for idx, proj in enumerate(PROJECTS):
|
|
| 49 |
suffix = f"_{i}" if idx < 3 else str(i)
|
| 50 |
img_path = f"images/projects/{prefix}{suffix}.png"
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
html += f'<img src="data:image/png;base64,{img_b64}" style="width: 100%; border-radius: 8px; border: 2px solid rgba(0,217,255,0.3);" loading="lazy">'
|
| 55 |
|
| 56 |
html += '</div><h3 style="color: #00D9FF; margin: 1.5rem 0 1rem;">🔗 Liens du projet</h3>'
|
| 57 |
html += '<div style="display: flex; gap: 1rem; flex-wrap: wrap;">'
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from config import PROJECTS
|
| 3 |
import base64
|
| 4 |
+
from pathlib import Path
|
| 5 |
|
| 6 |
st.set_page_config(page_title="Projets", page_icon="💼", layout="wide")
|
| 7 |
|
| 8 |
with open("styles.css", encoding="utf-8") as f:
|
| 9 |
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
|
| 10 |
|
| 11 |
+
# Cache persistent avec fichier
|
| 12 |
+
@st.cache_data(ttl=3600)
|
| 13 |
+
def load_all_images():
|
| 14 |
+
cache = {}
|
| 15 |
+
images = [
|
| 16 |
+
*[f"images/projects/dakar_{i}.png" for i in range(1, 5)],
|
| 17 |
+
*[f"images/projects/tidianeflix_{i}.png" for i in range(1, 5)],
|
| 18 |
+
*[f"images/projects/sentimentscope_{i}.png" for i in range(1, 5)],
|
| 19 |
+
*[f"images/projects/climate_change{i}.png" for i in range(1, 5)]
|
| 20 |
+
]
|
| 21 |
|
| 22 |
+
for img_path in images:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
try:
|
| 24 |
with open(img_path, "rb") as f:
|
| 25 |
+
cache[img_path] = base64.b64encode(f.read()).decode()
|
| 26 |
except:
|
| 27 |
+
cache[img_path] = None
|
| 28 |
+
|
| 29 |
+
return cache
|
| 30 |
+
|
| 31 |
+
# Charger AVEC cache Streamlit
|
| 32 |
+
images_cache = load_all_images()
|
| 33 |
|
| 34 |
html = '<h1 style="color: #00D9FF; text-align: center; margin-bottom: 3rem; font-weight: 800;">💼 Mes Projets Data Science</h1>'
|
| 35 |
|
|
|
|
| 55 |
suffix = f"_{i}" if idx < 3 else str(i)
|
| 56 |
img_path = f"images/projects/{prefix}{suffix}.png"
|
| 57 |
|
| 58 |
+
img_b64 = images_cache.get(img_path)
|
| 59 |
+
if img_b64:
|
| 60 |
+
html += f'<img src="data:image/png;base64,{img_b64}" style="width: 100%; border-radius: 8px; border: 2px solid rgba(0,217,255,0.3);" loading="lazy" decoding="async">'
|
| 61 |
|
| 62 |
html += '</div><h3 style="color: #00D9FF; margin: 1.5rem 0 1rem;">🔗 Liens du projet</h3>'
|
| 63 |
html += '<div style="display: flex; gap: 1rem; flex-wrap: wrap;">'
|
styles.css
CHANGED
|
@@ -335,3 +335,12 @@ header[data-testid="stHeader"] {
|
|
| 335 |
transform: scale(1.05) !important;
|
| 336 |
box-shadow: 0 8px 25px rgba(0, 217, 255, 0.6) !important;
|
| 337 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
transform: scale(1.05) !important;
|
| 336 |
box-shadow: 0 8px 25px rgba(0, 217, 255, 0.6) !important;
|
| 337 |
}
|
| 338 |
+
|
| 339 |
+
|
| 340 |
+
/* SIDEBAR STICKY - RESTE EN HAUT SANS COUVRIR */
|
| 341 |
+
[data-testid="stSidebar"] [data-testid="stSidebarUserContent"] {
|
| 342 |
+
position: sticky !important;
|
| 343 |
+
top: 0 !important;
|
| 344 |
+
max-height: 100vh !important;
|
| 345 |
+
overflow-y: auto !important;
|
| 346 |
+
}
|