-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
787 lines (684 loc) · 33.1 KB
/
Copy pathapp.py
File metadata and controls
787 lines (684 loc) · 33.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
import os
import re
import sys
# Ensure project root is on the path so sub-packages resolve correctly
sys.path.insert(0, os.path.dirname(__file__))
import streamlit as st
from dotenv import load_dotenv
load_dotenv()
# ── Page config ───────────────────────────────────────────────────────────────
st.set_page_config(
page_title="The Gender Norms Time Machine",
page_icon="⏳",
layout="wide",
initial_sidebar_state="collapsed",
)
# ── Global CSS ────────────────────────────────────────────────────────────────
st.markdown(
"""
<style>
.block-container { padding-top: 1.5rem; }
/* Typography */
.gtm-hero-title {
font-size: 2.6rem; font-weight: 800; text-align: center;
background: linear-gradient(135deg, #F26076 0%, #FF9760 55%, #FFD150 100%);
-webkit-background-clip: text; -webkit-text-fill-color: transparent;
line-height: 1.2; margin-bottom: 0.3rem;
}
.gtm-subtitle { font-size: 1.1rem; text-align: center; color: #666; margin-bottom: 1.2rem; }
/* Era/past sections — warm cream */
.era-card {
background: #FFF9F0;
border-left: 4px solid #458B73;
border-radius: 10px; padding: 1.2rem 1.4rem; margin: 0.8rem 0;
}
/* Future/whatif sections — coral warmth */
.whatif-card {
background: linear-gradient(135deg, #FFF9F0 0%, #FFE8E0 100%);
border-left: 4px solid #F26076;
border-radius: 10px; padding: 1.2rem 1.4rem; margin: 0.8rem 0;
}
/* Pull-quote */
.pull-quote {
border-left: 5px solid #458B73;
background: #f4faf7;
padding: 1.2rem 1.5rem;
border-radius: 0 10px 10px 0;
font-style: italic;
font-size: 1.0rem;
color: #444;
margin: 1rem 0;
}
.pull-quote-attribution {
font-style: normal; font-weight: 600; color: #458B73;
margin-top: 0.5rem; font-size: 0.9rem;
}
/* Micro-copy affirming */
.affirm-text { color: #458B73; font-style: italic; font-size: 0.95rem; text-align: center; margin: 0.5rem 0; }
/* Share card */
.share-card {
background: linear-gradient(135deg, #F26076 0%, #FF9760 55%, #FFD150 100%);
color: white; border-radius: 14px;
padding: 1.5rem 2rem; margin: 1rem 0;
text-align: center;
}
.share-card h3 { color: white; margin-bottom: 0.5rem; }
.share-card p { color: rgba(255,255,255,0.92); }
</style>
""",
unsafe_allow_html=True,
)
# ── Session state defaults ────────────────────────────────────────────────────
DEFAULTS = {
"page": "welcome",
"birth_year": None,
"gender_identity": None,
"sexuality": None,
"pressure_to_conform": None,
"felt_different": None,
"growing_up_decades": [],
"primary_decade": None,
"era_facts": [],
"reflection_questions": [],
"reflection_answers": {},
"experience_narrative": None,
"whatif_narrative": None,
}
for key, val in DEFAULTS.items():
if key not in st.session_state:
st.session_state[key] = val
# ── Navigation helper ─────────────────────────────────────────────────────────
def go(page: str) -> None:
st.session_state.page = page
st.rerun()
# ── Progress indicator ────────────────────────────────────────────────────────
PAGES = [
("welcome", "Welcome"),
("about_you", "About You"),
("reflection_questions", "Reflection"),
("results_dashboard", "Results"),
]
def render_progress() -> None:
current = st.session_state.page
page_keys = [p[0] for p in PAGES]
current_idx = page_keys.index(current) if current in page_keys else 0
cols = st.columns(len(PAGES))
for i, (key, label) in enumerate(PAGES):
with cols[i]:
if i < current_idx:
style = "background:#458B73;color:white;"
text = f"✓ {label}"
elif i == current_idx:
style = "background:#F26076;color:white;font-weight:700;"
text = label
else:
style = "background:#e0e0e0;color:#777;"
text = label
st.markdown(
f"<div style='{style}text-align:center;padding:0.4rem 0;"
f"border-radius:20px;font-size:0.82rem;'>{text}</div>",
unsafe_allow_html=True,
)
st.markdown("<br>", unsafe_allow_html=True)
# ═════════════════════════════════════════════════════════════════════════════
# PAGE 1 — WELCOME
# ═════════════════════════════════════════════════════════════════════════════
def page_welcome() -> None:
st.markdown(
"<h1 class='gtm-hero-title'>The Gender Norms Time Machine</h1>",
unsafe_allow_html=True,
)
st.markdown(
"<p class='gtm-subtitle'>A personal journey through a century of gender expectations</p>",
unsafe_allow_html=True,
)
render_progress()
# Pull-quote — creator's statement
st.markdown(
"""
<div class="pull-quote">
This app was born from a personal realization. Growing up surrounded by the heteronormativity of the
1980s and 1990s, I didn't realize that I was queer until decades
later. I built the Gender Norms Time Machine to explore a question that still moves me: how
different might my journey have been if I'd grown up with today's visibility, language,
and representation?
<div class="pull-quote-attribution">— The Creator</div>
</div>
""".strip(),
unsafe_allow_html=True,
)
st.markdown("---")
st.markdown("### About This Experience")
st.markdown(
"""
This app asks you to share a bit about yourself — your birth year and how you experienced
gender growing up — then uses AI to explore how history shaped you, and what might have
been different.
Using AI powered by [Claude](https://anthropic.com), it will:
- **Situate you in your historical era** with rich cultural context drawn from your birth year
- **Ask you 3 personal reflection questions** tailored to your era and identity
- **Generate a narrative** about how those years shaped your specific experience
- **Imagine an alternative** — what if you'd grown up in the 2020s with today's visibility?
---
"""
)
has_key = bool(os.getenv("ANTHROPIC_API_KEY", "").strip())
if not has_key:
st.warning(
"**API key not found.** Copy `.env.example` → `.env` and add your "
"`ANTHROPIC_API_KEY`, then restart the app."
)
st.markdown("")
if st.button("Begin Your Journey →", type="primary", use_container_width=True):
go("about_you")
# ═════════════════════════════════════════════════════════════════════════════
# PAGE 2 — ABOUT YOU
# ═════════════════════════════════════════════════════════════════════════════
def page_about_you() -> None:
from core.timeline_engine import load_decades, calculate_growing_up_decades, get_era_glance_facts
st.markdown(
"<h1 class='gtm-hero-title'>About You</h1>",
unsafe_allow_html=True,
)
st.markdown(
"<p class='gtm-subtitle'>Help us understand your experience growing up</p>",
unsafe_allow_html=True,
)
render_progress()
all_decades = load_decades()
left_col, right_col = st.columns(2)
with left_col:
birth_year_input = st.number_input(
"What year were you born?",
min_value=1920,
max_value=2010,
value=st.session_state.birth_year if st.session_state.birth_year else 1975,
step=1,
key="birth_year_widget",
)
gender_identity_input = st.selectbox(
"How did you identify your gender growing up?",
options=[
"-- Select --",
"Cisgender man",
"Cisgender woman",
"Transgender man",
"Transgender woman",
"Nonbinary/genderqueer",
"Genderfluid",
"Not sure / questioning",
"Prefer not to say",
],
index=0 if not st.session_state.gender_identity else [
"-- Select --",
"Cisgender man",
"Cisgender woman",
"Transgender man",
"Transgender woman",
"Nonbinary/genderqueer",
"Genderfluid",
"Not sure / questioning",
"Prefer not to say",
].index(st.session_state.gender_identity)
if st.session_state.gender_identity in [
"-- Select --",
"Cisgender man",
"Cisgender woman",
"Transgender man",
"Transgender woman",
"Nonbinary/genderqueer",
"Genderfluid",
"Not sure / questioning",
"Prefer not to say",
] else 0,
)
sexuality_input = st.selectbox(
"How did you identify your sexuality growing up?",
options=[
"-- Select --",
"Heterosexual / straight",
"Gay / lesbian",
"Bisexual",
"Pansexual",
"Asexual",
"Not sure / questioning",
"Prefer not to say",
],
index=0 if not st.session_state.sexuality else [
"-- Select --",
"Heterosexual / straight",
"Gay / lesbian",
"Bisexual",
"Pansexual",
"Asexual",
"Not sure / questioning",
"Prefer not to say",
].index(st.session_state.sexuality)
if st.session_state.sexuality in [
"-- Select --",
"Heterosexual / straight",
"Gay / lesbian",
"Bisexual",
"Pansexual",
"Asexual",
"Not sure / questioning",
"Prefer not to say",
] else 0,
)
with right_col:
pressure_input = st.selectbox(
"Did you feel pressure to conform to gender norms growing up?",
options=["-- Select --", "Yes, definitely", "Somewhat", "Not really", "No"],
index=0 if not st.session_state.pressure_to_conform else [
"-- Select --", "Yes, definitely", "Somewhat", "Not really", "No"
].index(st.session_state.pressure_to_conform)
if st.session_state.pressure_to_conform in [
"-- Select --", "Yes, definitely", "Somewhat", "Not really", "No"
] else 0,
)
felt_different_input = st.selectbox(
"Did you feel different from your peers around gender?",
options=["-- Select --", "Yes, definitely", "Somewhat", "Not really", "No"],
index=0 if not st.session_state.felt_different else [
"-- Select --", "Yes, definitely", "Somewhat", "Not really", "No"
].index(st.session_state.felt_different)
if st.session_state.felt_different in [
"-- Select --", "Yes, definitely", "Somewhat", "Not really", "No"
] else 0,
)
# ── Era at a Glance — renders immediately as birth year changes ───────────
if birth_year_input:
growing_decades = calculate_growing_up_decades(birth_year_input)
if growing_decades:
era_facts = get_era_glance_facts(growing_decades, all_decades)
# Build decade info lines
decade_info_lines = []
for dk in growing_decades:
if dk in all_decades:
dd = all_decades[dk]
decade_info_lines.append(
f"<strong>{dd.get('emoji', '')} {dd.get('label', dk)}</strong>: "
f"<em>{dd.get('tagline', '')}</em>"
)
decade_info_html = "<br>".join(decade_info_lines)
facts_html = "".join(
f"<li style='margin-bottom:0.3rem;'>{fact}</li>" for fact in era_facts
)
primary_growing_decade = growing_decades[len(growing_decades) // 2]
era_image_path = f"images/{primary_growing_decade}.webp"
img_col, card_col = st.columns([1, 2])
with img_col:
try:
st.image(era_image_path, use_container_width=True)
except Exception:
pass
with card_col:
st.markdown(
f"""
<div class="era-card" style="margin-top:0;height:100%;">
<h4 style="margin-top:0;color:#2d6a55;">Your Era at a Glance</h4>
<p style="margin-bottom:0.6rem;">You grew up across:</p>
<p style="margin-bottom:0.8rem;">{decade_info_html}</p>
<p style="font-weight:600;color:#2d6a55;margin-bottom:0.4rem;">
Here's what was happening around gender during those years:
</p>
<ul style="margin:0;padding-left:1.2rem;color:#3a4a42;">
{facts_html}
</ul>
</div>
""".strip(),
unsafe_allow_html=True,
)
st.markdown("---")
nav_back, nav_continue = st.columns([1, 2])
with nav_back:
if st.button("← Back", use_container_width=True):
go("welcome")
with nav_continue:
if st.button("Continue →", type="primary", use_container_width=True):
# Validate
errors = []
if gender_identity_input == "-- Select --":
errors.append("Please select your gender identity.")
if sexuality_input == "-- Select --":
errors.append("Please select your sexuality.")
if pressure_input == "-- Select --":
errors.append("Please answer the pressure to conform question.")
if felt_different_input == "-- Select --":
errors.append("Please answer the felt different question.")
if errors:
for err in errors:
st.warning(err)
else:
# Save to session state
st.session_state.birth_year = birth_year_input
st.session_state.gender_identity = gender_identity_input
st.session_state.sexuality = sexuality_input
st.session_state.pressure_to_conform = pressure_input
st.session_state.felt_different = felt_different_input
growing_decades = calculate_growing_up_decades(birth_year_input)
st.session_state.growing_up_decades = growing_decades
# Determine primary decade (middle of span)
if growing_decades:
primary_idx = len(growing_decades) // 2
st.session_state.primary_decade = growing_decades[primary_idx]
else:
st.session_state.primary_decade = None
# Store era facts
st.session_state.era_facts = get_era_glance_facts(growing_decades, all_decades)
# Reset downstream state
st.session_state.reflection_questions = []
st.session_state.reflection_answers = {}
st.session_state.experience_narrative = None
st.session_state.whatif_narrative = None
go("reflection_questions")
# ═════════════════════════════════════════════════════════════════════════════
# PAGE 3 — REFLECTION QUESTIONS
# ═════════════════════════════════════════════════════════════════════════════
def page_reflection_questions() -> None:
from core.timeline_engine import load_decades
from services.ai_generator import generate_reflection_questions
if not st.session_state.birth_year or not st.session_state.growing_up_decades:
st.error("Please complete the About You section first.")
if st.button("← Go Back"):
go("about_you")
return
all_decades = load_decades()
growing_up_decades = st.session_state.growing_up_decades
primary_decade_key = st.session_state.primary_decade or growing_up_decades[0]
primary_decade_data = all_decades.get(primary_decade_key, {})
primary_label = primary_decade_data.get("label", primary_decade_key)
st.markdown(
f"<h1 class='gtm-hero-title'>Reflecting on the {primary_label}</h1>",
unsafe_allow_html=True,
)
st.markdown(
"<p class='gtm-subtitle'>Answer honestly — from your own perspective today</p>",
unsafe_allow_html=True,
)
render_progress()
# ── Generate questions once ───────────────────────────────────────────────
if not st.session_state.reflection_questions:
if not os.getenv("ANTHROPIC_API_KEY", "").strip():
st.error(
"**API key required** to generate reflection questions. "
"Add your `ANTHROPIC_API_KEY` to `.env` and restart the app."
)
if st.button("← Back to About You"):
go("about_you")
return
with st.spinner("Generating your reflection questions..."):
try:
identity_info = {
"birth_year": st.session_state.birth_year,
"gender_identity": st.session_state.gender_identity,
"sexuality": st.session_state.sexuality,
"pressure_to_conform": st.session_state.pressure_to_conform,
"felt_different": st.session_state.felt_different,
}
questions = generate_reflection_questions(
growing_up_decades, all_decades, identity_info
)
st.session_state.reflection_questions = questions
st.rerun()
except Exception as e:
st.error(f"Error generating questions: {e}")
if st.button("← Back"):
go("about_you")
return
questions = st.session_state.reflection_questions
st.markdown("")
# ── Reflection form ───────────────────────────────────────────────────────
with st.form("reflection_form"):
answers = {}
for i, question in enumerate(questions):
st.markdown(
f"""
<div class="era-card">
<p style="font-weight:600;margin-bottom:0.5rem;color:#8B6914;">
Question {i + 1}
</p>
<p style="margin:0;color:#3d2b00;">{question}</p>
</div>
""".strip(),
unsafe_allow_html=True,
)
answers[f"q{i + 1}"] = st.text_area(
label=f"answer_{i + 1}",
value=st.session_state.reflection_answers.get(f"q{i + 1}", ""),
height=110,
placeholder="Share your thoughts honestly...",
label_visibility="collapsed",
)
if i < len(questions) - 1:
st.markdown("")
st.markdown("")
form_cols = st.columns([1, 2])
with form_cols[0]:
back_btn = st.form_submit_button("← Back")
with form_cols[1]:
submit_btn = st.form_submit_button("Reveal My Story →", type="primary")
if back_btn:
go("about_you")
if submit_btn:
filled = sum(1 for v in answers.values() if v.strip())
if filled < 2:
st.warning("Please answer at least **2 questions** before continuing.")
else:
st.session_state.reflection_answers = answers
st.session_state.experience_narrative = None
st.session_state.whatif_narrative = None
go("results_dashboard")
# ═════════════════════════════════════════════════════════════════════════════
# PAGE 4 — RESULTS DASHBOARD
# ═════════════════════════════════════════════════════════════════════════════
def page_results_dashboard() -> None:
from core.timeline_engine import load_decades
from services.ai_generator import generate_experience_narrative, generate_whatif_narrative
from visualization.charts import (
create_timeline_chart,
create_era_vs_2020s_chart,
)
if not st.session_state.birth_year or not st.session_state.reflection_answers:
st.error("Please complete the reflection questions first.")
if st.button("← Go to Reflection Questions"):
go("reflection_questions")
return
all_decades = load_decades()
growing_up_decades = st.session_state.growing_up_decades
primary_decade_key = st.session_state.primary_decade or (growing_up_decades[0] if growing_up_decades else None)
if not primary_decade_key:
st.error("Could not determine your primary decade. Please go back.")
if st.button("← Back"):
go("about_you")
return
primary_decade_data = all_decades.get(primary_decade_key, {})
primary_label = primary_decade_data.get("label", primary_decade_key)
# Build decade label span for display
decade_labels_list = []
for dk in growing_up_decades:
if dk in all_decades:
decade_labels_list.append(all_decades[dk].get("label", dk))
primary_decades_label = " & ".join(decade_labels_list) if decade_labels_list else primary_label
st.markdown(
"<h1 class='gtm-hero-title'>Your Story</h1>",
unsafe_allow_html=True,
)
st.markdown(
f"<p class='gtm-subtitle'>How the {primary_decades_label} shaped you — and what might have been</p>",
unsafe_allow_html=True,
)
render_progress()
# ── Generate narratives if not yet generated ──────────────────────────────
identity_info = {
"birth_year": st.session_state.birth_year,
"gender_identity": st.session_state.gender_identity,
"sexuality": st.session_state.sexuality,
"pressure_to_conform": st.session_state.pressure_to_conform,
"felt_different": st.session_state.felt_different,
}
needs_generation = (
not st.session_state.experience_narrative
or not st.session_state.whatif_narrative
)
if needs_generation:
if not os.getenv("ANTHROPIC_API_KEY", "").strip():
st.session_state.experience_narrative = (
"_AI narrative unavailable — no API key provided. "
"Add your `ANTHROPIC_API_KEY` to `.env` and restart._"
)
st.session_state.whatif_narrative = (
"_AI narrative unavailable — no API key provided._"
)
else:
gen_container = st.container()
with gen_container:
st.markdown("### Exploring your journey through history...")
for fact in st.session_state.era_facts:
st.info(fact)
with st.spinner("Claude is writing your personal narrative..."):
try:
if not st.session_state.experience_narrative:
st.session_state.experience_narrative = generate_experience_narrative(
birth_year=st.session_state.birth_year,
growing_up_decades=growing_up_decades,
all_decades=all_decades,
identity_info=identity_info,
answers=st.session_state.reflection_answers,
questions=st.session_state.reflection_questions,
)
if not st.session_state.whatif_narrative:
st.session_state.whatif_narrative = generate_whatif_narrative(
identity_info=identity_info,
all_decades=all_decades,
)
st.rerun()
except Exception as e:
st.session_state.experience_narrative = f"_Error generating narrative: {e}_"
st.session_state.whatif_narrative = f"_Error generating narrative: {e}_"
experience_narrative = st.session_state.experience_narrative or ""
whatif_narrative = st.session_state.whatif_narrative or ""
# ═══════════════════════════════════════════════════════════════════════
# SECTION 1: Your Growing Up Era
# ═══════════════════════════════════════════════════════════════════════
decades_emoji_str = " ".join(
all_decades[dk].get("emoji", "") for dk in growing_up_decades if dk in all_decades
)
st.markdown(
f"""
<div class="era-card">
<h3 style="margin-top:0;color:#8B6914;">Your Growing Up Era</h3>
<p style="color:#5a3e10;margin-bottom:0;">
{decades_emoji_str} You grew up across the <strong>{primary_decades_label}</strong>
</p>
</div>
""".strip(),
unsafe_allow_html=True,
)
timeline_fig = create_timeline_chart(all_decades, primary_decade_key)
st.plotly_chart(timeline_fig, use_container_width=True)
# Comparison bar: their era vs 2020s
st.markdown("#### How Much Has Changed Since Your Growing Up Years?")
era_vs_fig = create_era_vs_2020s_chart(all_decades, primary_decade_key)
st.plotly_chart(era_vs_fig, use_container_width=True)
st.markdown("---")
# ═══════════════════════════════════════════════════════════════════════
# SECTION 2: Your Experience
# ═══════════════════════════════════════════════════════════════════════
st.markdown(
"""
<div class="era-card">
<h3 style="margin-top:0;color:#8B6914;">How Those Years Shaped You</h3>
</div>
""".strip(),
unsafe_allow_html=True,
)
st.markdown(experience_narrative)
# Reflection Q&A in expanders
questions = st.session_state.reflection_questions
answers = st.session_state.reflection_answers
if questions and answers:
st.markdown("**Your reflection responses:**")
for i, (key, answer) in enumerate(answers.items()):
if answer.strip() and i < len(questions):
short_q = questions[i][:80] + ("..." if len(questions[i]) > 80 else "")
with st.expander(f"Q{i + 1}: {short_q}"):
st.write(answer)
st.markdown("---")
# ═══════════════════════════════════════════════════════════════════════
# SECTION 3: What If You Were Born Today?
# ═══════════════════════════════════════════════════════════════════════
st.markdown(
"""
<div class="whatif-card">
<h3 style="margin-top:0;color:#1565C0;">What If You'd Grown Up in the 2020s?</h3>
</div>
""".strip(),
unsafe_allow_html=True,
)
st.markdown(whatif_narrative)
# Local images for 2020s section
whatif_local_images = ["images/nonbinary.webp", "images/pride_bracelet.webp", "images/pride_skirt.webp"]
whatif_img_cols = st.columns(3)
for i, img_path in enumerate(whatif_local_images):
with whatif_img_cols[i]:
try:
st.image(img_path, use_container_width=True)
except Exception:
pass
st.markdown("---")
# ═══════════════════════════════════════════════════════════════════════
# SHARE CARD
# ═══════════════════════════════════════════════════════════════════════
birth_year = st.session_state.birth_year
gender_identity = st.session_state.gender_identity or ""
sexuality = st.session_state.sexuality or ""
# Extract first sentence from experience_narrative (strip markdown)
first_sentence = ""
if experience_narrative:
clean_text = re.sub(r"[#*_`]", "", experience_narrative)
parts = clean_text.split(".")
if parts:
first_sentence = parts[0].strip() + "."
st.markdown(
f"""
<div class="share-card">
<h3>The Gender Norms Time Machine</h3>
<p>Born {birth_year} · {gender_identity} · {sexuality}</p>
<p>Growing up era: {primary_decades_label}</p>
<p style="font-style:italic;margin-top:0.8rem;">{first_sentence}</p>
<p style="font-size:0.8rem;opacity:0.8;margin-top:0.5rem;">Screenshot to share your story</p>
</div>
""".strip(),
unsafe_allow_html=True,
)
# ── Navigation ────────────────────────────────────────────────────────────
st.markdown("---")
nav1, nav2 = st.columns(2)
with nav1:
if st.button("← Explore Another Era", use_container_width=True):
# Reset to about_you, preserve birth year and identity info
st.session_state.growing_up_decades = []
st.session_state.primary_decade = None
st.session_state.era_facts = []
st.session_state.reflection_questions = []
st.session_state.reflection_answers = {}
st.session_state.experience_narrative = None
st.session_state.whatif_narrative = None
go("about_you")
with nav2:
if st.button("Start Over", use_container_width=True):
for k in list(st.session_state.keys()):
del st.session_state[k]
go("welcome")
# ═════════════════════════════════════════════════════════════════════════════
# ROUTER
# ═════════════════════════════════════════════════════════════════════════════
ROUTE_MAP = {
"welcome": page_welcome,
"about_you": page_about_you,
"reflection_questions": page_reflection_questions,
"results_dashboard": page_results_dashboard,
}
current = st.session_state.get("page", "welcome")
ROUTE_MAP.get(current, page_welcome)()