idiouf commited on
Commit
5f7b3bc
·
verified ·
1 Parent(s): a22f12f

Upload 18 files

Browse files
Files changed (3) hide show
  1. Dockerfile +18 -14
  2. README.md +29 -7
  3. app.py +32 -9
Dockerfile CHANGED
@@ -3,7 +3,8 @@ FROM python:3.11-slim
3
  ENV PYTHONDONTWRITEBYTECODE=1 \
4
  PYTHONUNBUFFERED=1 \
5
  PIP_NO_CACHE_DIR=1 \
6
- CONSERVATION_HD_CACHE=/tmp/conservation_hd_cache
 
7
 
8
  WORKDIR /app
9
 
@@ -19,19 +20,22 @@ EXPOSE 7860
19
 
20
  HEALTHCHECK CMD python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:7860/_stcore/health')"
21
 
22
- # The two palettes are passed as flags rather than a .streamlit/config.toml so the
23
- # repository stays a single flat folder. Streamlit then follows the reader's own
24
- # light/dark setting and themes its native widgets to match the app's own CSS.
25
- # Do not add a plain --theme.<key> flag here: one top-level key collapses both
26
- # palettes into a single custom theme and disables light/dark switching.
 
 
 
 
 
 
27
  CMD ["streamlit", "run", "app.py", \
28
  "--server.address=0.0.0.0", "--server.port=7860", \
29
  "--server.headless=true", "--browser.gatherUsageStats=false", \
30
- "--theme.light.backgroundColor=#F2F6FA", \
31
- "--theme.light.secondaryBackgroundColor=#FFFFFF", \
32
- "--theme.light.textColor=#0F2439", \
33
- "--theme.light.primaryColor=#1668CE", \
34
- "--theme.dark.backgroundColor=#070F1A", \
35
- "--theme.dark.secondaryBackgroundColor=#0D1E30", \
36
- "--theme.dark.textColor=#F2F7FC", \
37
- "--theme.dark.primaryColor=#4A9BFF"]
 
3
  ENV PYTHONDONTWRITEBYTECODE=1 \
4
  PYTHONUNBUFFERED=1 \
5
  PIP_NO_CACHE_DIR=1 \
6
+ CONSERVATION_HD_CACHE=/tmp/conservation_hd_cache \
7
+ CONSERVATION_HD_THEME=dark
8
 
9
  WORKDIR /app
10
 
 
20
 
21
  HEALTHCHECK CMD python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:7860/_stcore/health')"
22
 
23
+ # One pinned dark palette, passed as flags so the repository stays a flat folder.
24
+ #
25
+ # Streamlit has two mutually exclusive modes here, and they are easy to confuse:
26
+ # · top-level --theme.* keys → ONE fixed custom theme, ignores the browser.
27
+ # · --theme.light.* + --theme.dark.* (and no top-level key) → follows the
28
+ # reader's own light/dark setting; --theme.base is then ignored entirely.
29
+ # Dark is the default the app is designed around, so the top-level form is used
30
+ # and CONSERVATION_HD_THEME=dark keeps the app's own CSS in step with it.
31
+ #
32
+ # To follow the reader instead: set CONSERVATION_HD_THEME=auto and swap the four
33
+ # flags below for the per-mode pairs documented in the README.
34
  CMD ["streamlit", "run", "app.py", \
35
  "--server.address=0.0.0.0", "--server.port=7860", \
36
  "--server.headless=true", "--browser.gatherUsageStats=false", \
37
+ "--theme.base=dark", \
38
+ "--theme.backgroundColor=#070F1A", \
39
+ "--theme.secondaryBackgroundColor=#0D1E30", \
40
+ "--theme.textColor=#F2F7FC", \
41
+ "--theme.primaryColor=#4A9BFF"]
 
 
 
README.md CHANGED
@@ -70,28 +70,49 @@ method** page always shows how old the snapshot is.
70
  | `app.py` | The Streamlit dashboard: six pages, bilingual, mobile-first |
71
  | `sources.py` | Data connectors, disk caching and the status each one reports |
72
  | `analysis.py` | The Li et al. typology, spatial joins and derived measures |
73
- | `Dockerfile` | Build for the Space; also carries the light and dark palettes |
74
  | `requirements.txt` | Pinned dependencies |
75
  | `selftest.py` | Runs every connector and prints what answered |
76
  | `prefetch.py` | Downloads everything once and writes a `cache_*` snapshot to commit |
 
77
  | `make_fixtures.py`, `test_app.py`, `fixture_*` | Offline test doubles and the 37-check suite. Safe to delete from the Space; keep them if you want to re-run the tests. |
78
 
79
- ### Running it locally
80
 
81
- The two palettes are flags, not a config file, so pass them through:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
 
83
  ```bash
84
  pip install -r requirements.txt
85
- streamlit run app.py \
 
 
 
 
 
 
 
 
 
86
  --theme.light.backgroundColor="#F2F6FA" --theme.light.secondaryBackgroundColor="#FFFFFF" \
87
  --theme.light.textColor="#0F2439" --theme.light.primaryColor="#1668CE" \
88
  --theme.dark.backgroundColor="#070F1A" --theme.dark.secondaryBackgroundColor="#0D1E30" \
89
  --theme.dark.textColor="#F2F7FC" --theme.dark.primaryColor="#4A9BFF"
90
  ```
91
 
92
- Never add a plain `--theme.<key>` flag alongside these: one top-level key collapses both
93
- palettes into a single custom theme and disables light/dark switching.
94
-
95
  To re-run the offline test suite:
96
 
97
  ```bash
@@ -108,6 +129,7 @@ python test_app.py # 37 checks: analysis layer + every page in both langu
108
  | `SHDI_CSV_URL` | Direct link (or local path) to the Global Data Lab SHDI csv, to move from country averages to subnational regions |
109
  | `CONSERVATION_HD_CACHE` | Where to cache downloads (default: a `conservation_hd_cache` folder in the system temp directory) |
110
  | `CONSERVATION_HD_CACHE_TTL` | Cache lifetime in seconds (default 7 days) |
 
111
 
112
  ### Checking the connectors
113
 
 
70
  | `app.py` | The Streamlit dashboard: six pages, bilingual, mobile-first |
71
  | `sources.py` | Data connectors, disk caching and the status each one reports |
72
  | `analysis.py` | The Li et al. typology, spatial joins and derived measures |
73
+ | `Dockerfile` | Build for the Space; also carries the pinned dark palette |
74
  | `requirements.txt` | Pinned dependencies |
75
  | `selftest.py` | Runs every connector and prints what answered |
76
  | `prefetch.py` | Downloads everything once and writes a `cache_*` snapshot to commit |
77
+ | `record_demo.py`, `narration.md` | Records a 3-minute guided tour as `demo.mp4`, with voice-over text |
78
  | `make_fixtures.py`, `test_app.py`, `fixture_*` | Offline test doubles and the 37-check suite. Safe to delete from the Space; keep them if you want to re-run the tests. |
79
 
80
+ ### Theme
81
 
82
+ The dashboard ships **dark by default**, for every reader, whatever their browser is set
83
+ to. The palette is passed as flags rather than a config file so the repository stays a
84
+ flat folder.
85
+
86
+ Streamlit has two mutually exclusive theming modes here, and mixing them silently breaks
87
+ one of them:
88
+
89
+ | Flags | Behaviour |
90
+ |---|---|
91
+ | top-level `--theme.*` | one fixed custom theme; the browser setting is ignored |
92
+ | `--theme.light.*` + `--theme.dark.*`, no top-level key | follows the reader's own light/dark setting; `--theme.base` is then ignored entirely |
93
+
94
+ The Space uses the first form. `CONSERVATION_HD_THEME=dark` keeps the app's own CSS in
95
+ step with it — without that the CSS would still follow the browser and a reader on a
96
+ light system would get light cards on dark chrome.
97
 
98
  ```bash
99
  pip install -r requirements.txt
100
+ CONSERVATION_HD_THEME=dark streamlit run app.py \
101
+ --theme.base=dark \
102
+ --theme.backgroundColor="#070F1A" --theme.secondaryBackgroundColor="#0D1E30" \
103
+ --theme.textColor="#F2F7FC" --theme.primaryColor="#4A9BFF"
104
+ ```
105
+
106
+ To follow the reader instead, set `CONSERVATION_HD_THEME=auto` and swap the four flags
107
+ for the per-mode pairs:
108
+
109
+ ```bash
110
  --theme.light.backgroundColor="#F2F6FA" --theme.light.secondaryBackgroundColor="#FFFFFF" \
111
  --theme.light.textColor="#0F2439" --theme.light.primaryColor="#1668CE" \
112
  --theme.dark.backgroundColor="#070F1A" --theme.dark.secondaryBackgroundColor="#0D1E30" \
113
  --theme.dark.textColor="#F2F7FC" --theme.dark.primaryColor="#4A9BFF"
114
  ```
115
 
 
 
 
116
  To re-run the offline test suite:
117
 
118
  ```bash
 
129
  | `SHDI_CSV_URL` | Direct link (or local path) to the Global Data Lab SHDI csv, to move from country averages to subnational regions |
130
  | `CONSERVATION_HD_CACHE` | Where to cache downloads (default: a `conservation_hd_cache` folder in the system temp directory) |
131
  | `CONSERVATION_HD_CACHE_TTL` | Cache lifetime in seconds (default 7 days) |
132
+ | `CONSERVATION_HD_THEME` | `dark` (default), `light`, or `auto` to follow the reader — see Theme above |
133
 
134
  ### Checking the connectors
135
 
app.py CHANGED
@@ -39,11 +39,15 @@ AUTHOR = {
39
  "name": "Dr. Ibrahima Diouf",
40
  "affiliation": "UCAD–ESP/LPAO-SF · Université de Labé–FST",
41
  "links": [
42
- ("Site", "https://scientific-hub-lab.github.io/Dr-Ibrahima-Diouf/"),
43
- ("Hugging Face", "https://huggingface.co/idiouf"),
44
- ("ORCID", "https://orcid.org/0000-0002-3157-0925"),
45
- ("LinkedIn", "https://www.linkedin.com/in/dr-ibrahima-diouf-610872108/"),
46
- ("Google Scholar", "https://scholar.google.com/citations?user=phsMm7sAAAAJ&hl=fr"),
 
 
 
 
47
  ],
48
  }
49
 
@@ -214,7 +218,16 @@ def stretch(fn) -> dict:
214
  return _WIDTH_CACHE[key]
215
 
216
 
 
 
 
 
 
 
 
217
  def active_theme() -> str:
 
 
218
  try:
219
  return "Light" if st.context.theme.type == "light" else "Dark"
220
  except Exception:
@@ -349,7 +362,14 @@ div[data-testid="stExpander"] { border:1px solid var(--border) !important;
349
  .sig-links a { display:inline-flex; align-items:center; padding:7px 14px; border-radius:999px;
350
  border:1px solid var(--border); background:var(--panel); color:var(--text) !important;
351
  text-decoration:none; font-size:.8rem; font-weight:650; min-height:38px; }
 
 
 
 
 
352
  .sig-links a:hover { border-color:var(--accent); background:var(--accent); color:#fff !important; }
 
 
353
  .sig-meta { color:var(--muted); font-size:.76rem; line-height:1.7; }
354
  .side-links { display:flex; flex-wrap:wrap; gap:6px; margin-top:4px; }
355
  .side-links a { font-size:.72rem; font-weight:650; padding:5px 10px; border-radius:999px;
@@ -605,7 +625,8 @@ with st.sidebar:
605
  language = st.radio(TEXT["English"]["language"], ["English", "Français"],
606
  horizontal=True, key="lang")
607
  t = TEXT[language]
608
- st.caption(f"{t['appearance']} · {t['theme_hint']}")
 
609
 
610
  st.markdown(CSS.substitute(**{k: v for k, v in palette.items() if k != "map_style"}),
611
  unsafe_allow_html=True)
@@ -693,7 +714,8 @@ with st.sidebar:
693
 
694
  st.markdown(f'<div class="side-label">{AUTHOR["name"]}</div>', unsafe_allow_html=True)
695
  st.markdown('<div class="side-links">' + "".join(
696
- f'<a href="{u}" target="_blank" rel="noopener">{n}</a>' for n, u in AUTHOR["links"]
 
697
  ) + "</div>", unsafe_allow_html=True)
698
 
699
  effectiveness = pd.DataFrame()
@@ -1306,8 +1328,9 @@ st.markdown(
1306
  <div class="sig-name">{AUTHOR['name']}</div>
1307
  <div class="sig-affil">{AUTHOR['affiliation']}</div>
1308
  <div class="sig-links">
1309
- {''.join(f'<a href="{u}" target="_blank" rel="noopener">{n}</a>'
1310
- for n, u in AUTHOR['links'])}
 
1311
  </div>
1312
  <div class="sig-meta">
1313
  © 2026 · <b>Conservation &amp; Human Development in Africa</b><br>
 
39
  "name": "Dr. Ibrahima Diouf",
40
  "affiliation": "UCAD–ESP/LPAO-SF · Université de Labé–FST",
41
  "links": [
42
+ ("🌐", "Website", "https://scientific-hub-lab.github.io/Dr-Ibrahima-Diouf/"),
43
+ ("🤗", "Hugging Face", "https://huggingface.co/idiouf"),
44
+ ("🆔", "ORCID", "https://orcid.org/0000-0002-3157-0925"),
45
+ ("in", "LinkedIn", "https://www.linkedin.com/in/dr-ibrahima-diouf-610872108/"),
46
+ ("🎓", "Google Scholar",
47
+ "https://scholar.google.com/citations?user=phsMm7sAAAAJ&hl=fr"),
48
+ ("🔗", "This Space",
49
+ "https://huggingface.co/spaces/idiouf/"
50
+ "African-Conservation-Human-Development-Observatory"),
51
  ],
52
  }
53
 
 
218
  return _WIDTH_CACHE[key]
219
 
220
 
221
+ # The Space pins a single dark theme (see the Dockerfile), so the CSS must not
222
+ # follow the browser — that would put light cards on a dark chrome. Set
223
+ # CONSERVATION_HD_THEME=auto, together with the two-palette flags, to go back to
224
+ # following the reader's own light/dark setting.
225
+ FORCED_THEME = os.environ.get("CONSERVATION_HD_THEME", "dark").strip().lower()
226
+
227
+
228
  def active_theme() -> str:
229
+ if FORCED_THEME in ("dark", "light"):
230
+ return FORCED_THEME.capitalize()
231
  try:
232
  return "Light" if st.context.theme.type == "light" else "Dark"
233
  except Exception:
 
362
  .sig-links a { display:inline-flex; align-items:center; padding:7px 14px; border-radius:999px;
363
  border:1px solid var(--border); background:var(--panel); color:var(--text) !important;
364
  text-decoration:none; font-size:.8rem; font-weight:650; min-height:38px; }
365
+ .sig-links a { gap:8px; }
366
+ .sig-links a .ic, .side-links a .ic {
367
+ font-size:.9em; opacity:.85; font-style:normal; font-weight:700; line-height:1;
368
+ }
369
+ .sig-links a span:not(.ic) { text-decoration:underline; text-underline-offset:3px; }
370
  .sig-links a:hover { border-color:var(--accent); background:var(--accent); color:#fff !important; }
371
+ .sig-links a:hover .ic { opacity:1; }
372
+ .side-links a { display:inline-flex; align-items:center; gap:5px; }
373
  .sig-meta { color:var(--muted); font-size:.76rem; line-height:1.7; }
374
  .side-links { display:flex; flex-wrap:wrap; gap:6px; margin-top:4px; }
375
  .side-links a { font-size:.72rem; font-weight:650; padding:5px 10px; border-radius:999px;
 
625
  language = st.radio(TEXT["English"]["language"], ["English", "Français"],
626
  horizontal=True, key="lang")
627
  t = TEXT[language]
628
+ if FORCED_THEME not in ("dark", "light"):
629
+ st.caption(f"{t['appearance']} · {t['theme_hint']}")
630
 
631
  st.markdown(CSS.substitute(**{k: v for k, v in palette.items() if k != "map_style"}),
632
  unsafe_allow_html=True)
 
714
 
715
  st.markdown(f'<div class="side-label">{AUTHOR["name"]}</div>', unsafe_allow_html=True)
716
  st.markdown('<div class="side-links">' + "".join(
717
+ f'<a href="{u}" target="_blank" rel="noopener">'
718
+ f'<span class="ic">{i}</span>{n}</a>' for i, n, u in AUTHOR["links"]
719
  ) + "</div>", unsafe_allow_html=True)
720
 
721
  effectiveness = pd.DataFrame()
 
1328
  <div class="sig-name">{AUTHOR['name']}</div>
1329
  <div class="sig-affil">{AUTHOR['affiliation']}</div>
1330
  <div class="sig-links">
1331
+ {''.join(f'<a href="{u}" target="_blank" rel="noopener">'
1332
+ f'<span class="ic">{i}</span>{n}</a>'
1333
+ for i, n, u in AUTHOR['links'])}
1334
  </div>
1335
  <div class="sig-meta">
1336
  © 2026 · <b>Conservation &amp; Human Development in Africa</b><br>