cheikhaidev-ui Claude Sonnet 4.6 commited on
Commit ·
1927413
1
Parent(s): 3493cb1
docs(images): regenerate screenshots post-coherence fixes
Browse filesScreenshots were outdated (old tab names Analytics/Export, old
quartier list). Regenerated from the live HF Space after:
- tabs renamed: Statistiques + Historique (was Analytics)
- quartiers corrected: Sicap-Liberte, Yoff, Mermoz, Fann
- viewport 1920x1080 for sharper carte.png
Also adds scripts/take_screenshots.py (Playwright + system Chrome)
as reusable tooling for future screenshot updates.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- images/analytics.png +2 -2
- images/carte.png +2 -2
- images/prediction.png +2 -2
- scripts/take_screenshots.py +123 -0
images/analytics.png
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
images/carte.png
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
images/prediction.png
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
scripts/take_screenshots.py
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Génération automatique des captures d'écran — Dakar Power Prediction
|
| 3 |
+
Cible : Space HF https://tijaani-dakar-power-prediction.hf.space/
|
| 4 |
+
Usage : python scripts/take_screenshots.py
|
| 5 |
+
"""
|
| 6 |
+
import asyncio
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
from playwright.async_api import async_playwright, TimeoutError as PWTimeout
|
| 9 |
+
|
| 10 |
+
SPACE_URL = "https://tijaani-dakar-power-prediction.hf.space/"
|
| 11 |
+
IMAGES_DIR = Path(__file__).parent.parent / "images"
|
| 12 |
+
VIEWPORT = {"width": 1920, "height": 1080}
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
async def wait_streamlit(page):
|
| 16 |
+
"""Attend que Streamlit soit complètement rendu (DOM + réseau + Plotly)."""
|
| 17 |
+
await page.wait_for_selector('[data-testid="stAppViewContainer"]', timeout=90_000)
|
| 18 |
+
# Laisse le WebSocket Streamlit s'établir et les composants se monter
|
| 19 |
+
await asyncio.sleep(4)
|
| 20 |
+
# Si un spinner tourne encore, on attend qu'il disparaisse
|
| 21 |
+
try:
|
| 22 |
+
await page.wait_for_selector(
|
| 23 |
+
'[data-testid="stSpinner"]', state="hidden", timeout=15_000
|
| 24 |
+
)
|
| 25 |
+
except PWTimeout:
|
| 26 |
+
pass
|
| 27 |
+
await asyncio.sleep(2)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
async def wait_plotly(page, timeout=20_000):
|
| 31 |
+
"""Attend qu'au moins un graphique Plotly soit rendu."""
|
| 32 |
+
await page.wait_for_selector(".js-plotly-plot", timeout=timeout)
|
| 33 |
+
# Plotly anime ses graphiques — on attend la fin du paint
|
| 34 |
+
await asyncio.sleep(3)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
async def click_tab(page, index: int):
|
| 38 |
+
"""Clique sur l'onglet Streamlit à l'index donné (0-based) et attend le rendu."""
|
| 39 |
+
tabs = page.get_by_role("tab")
|
| 40 |
+
await tabs.nth(index).click()
|
| 41 |
+
await asyncio.sleep(1)
|
| 42 |
+
try:
|
| 43 |
+
await page.wait_for_selector(
|
| 44 |
+
'[data-testid="stSpinner"]', state="hidden", timeout=10_000
|
| 45 |
+
)
|
| 46 |
+
except PWTimeout:
|
| 47 |
+
pass
|
| 48 |
+
await asyncio.sleep(2)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
async def main():
|
| 52 |
+
IMAGES_DIR.mkdir(exist_ok=True)
|
| 53 |
+
|
| 54 |
+
async with async_playwright() as pw:
|
| 55 |
+
browser = await pw.chromium.launch(
|
| 56 |
+
channel="chrome", # utilise Chrome système — hérite du réseau Windows
|
| 57 |
+
headless=True,
|
| 58 |
+
args=["--no-sandbox", "--disable-dev-shm-usage"],
|
| 59 |
+
)
|
| 60 |
+
page = await browser.new_page(viewport=VIEWPORT)
|
| 61 |
+
|
| 62 |
+
# ── Chargement initial ──────────────────────────────────────────────
|
| 63 |
+
print(f"-> Ouverture du Space : {SPACE_URL}")
|
| 64 |
+
await page.goto(SPACE_URL, wait_until="domcontentloaded", timeout=90_000)
|
| 65 |
+
await wait_streamlit(page)
|
| 66 |
+
print(" OK Streamlit prêt\n")
|
| 67 |
+
|
| 68 |
+
# ── 1. Prédiction ───────────────────────────────────────────────────
|
| 69 |
+
print("-> [1/3] prediction.png")
|
| 70 |
+
# L'onglet Prédiction est actif par défaut — on lance une prédiction
|
| 71 |
+
btn_pred = page.get_by_role("button", name="Lancer la Prédiction")
|
| 72 |
+
await btn_pred.click()
|
| 73 |
+
await wait_plotly(page) # attend la jauge Plotly
|
| 74 |
+
await asyncio.sleep(1) # marge pour le paint final
|
| 75 |
+
await page.screenshot(path=str(IMAGES_DIR / "prediction.png"))
|
| 76 |
+
print(" OK images/prediction.png\n")
|
| 77 |
+
|
| 78 |
+
# ── 2. Carte ────────────────────────────────────────────────────────
|
| 79 |
+
print("-> [2/3] carte.png")
|
| 80 |
+
await click_tab(page, 1) # index 1 = 🗺️ Carte
|
| 81 |
+
await asyncio.sleep(4)
|
| 82 |
+
# Si le map Plotly est déjà là (session réutilisée), on le prend directement.
|
| 83 |
+
# Sinon on clique le bouton via JavaScript pour contourner l'emoji dans le sélecteur.
|
| 84 |
+
map_present = await page.locator(".js-plotly-plot").count()
|
| 85 |
+
if map_present == 0:
|
| 86 |
+
print(" -> map absente, clic bouton via JS...")
|
| 87 |
+
await page.evaluate("""
|
| 88 |
+
() => {
|
| 89 |
+
const btns = [...document.querySelectorAll('button')];
|
| 90 |
+
const btn = btns.find(b => b.innerText.includes('Calculer'));
|
| 91 |
+
if (btn) btn.click();
|
| 92 |
+
}
|
| 93 |
+
""")
|
| 94 |
+
await wait_plotly(page, timeout=40_000)
|
| 95 |
+
else:
|
| 96 |
+
print(" -> map deja rendue, capture directe")
|
| 97 |
+
await asyncio.sleep(2)
|
| 98 |
+
await page.screenshot(path=str(IMAGES_DIR / "carte.png"))
|
| 99 |
+
print(" OK images/carte.png\n")
|
| 100 |
+
|
| 101 |
+
# ── 3. Statistiques ─────────────────────────────────────────────────
|
| 102 |
+
print("-> [3/3] analytics.png")
|
| 103 |
+
await click_tab(page, 2) # index 2 = 📊 Statistiques
|
| 104 |
+
# Le tab Streamlit charge le CSV + bar chart automatiquement.
|
| 105 |
+
# On attend via le dataframe (st.dataframe) plutôt que Plotly
|
| 106 |
+
# pour éviter de matcher les 8 graphiques cachés des tabs précédents.
|
| 107 |
+
try:
|
| 108 |
+
await page.wait_for_selector(
|
| 109 |
+
'[data-testid="stDataFrame"]', timeout=20_000
|
| 110 |
+
)
|
| 111 |
+
except PWTimeout:
|
| 112 |
+
pass # Si pas de dataframe visible, on screenshot quand même
|
| 113 |
+
await asyncio.sleep(4) # Laisse le bar chart finir son rendu
|
| 114 |
+
await page.screenshot(path=str(IMAGES_DIR / "analytics.png"))
|
| 115 |
+
print(" OK images/analytics.png\n")
|
| 116 |
+
|
| 117 |
+
await browser.close()
|
| 118 |
+
|
| 119 |
+
print("OK Toutes les captures générées dans images/")
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
if __name__ == "__main__":
|
| 123 |
+
asyncio.run(main())
|