@@ -110,9 +110,20 @@ def get_user_selections():
110110 # Determine default species index - maintain selection across reruns
111111 default_index = 0
112112
113- # If we have a previously selected species, try to find its index
113+ # Clean up old session state variable if it exists
114114 if "selected_species_display" in st .session_state :
115- default_index = display_names .index (st .session_state .selected_species_display )
115+ del st .session_state .selected_species_display
116+
117+ # If we have a previously selected species (stored as scientific name), find it
118+ if "selected_species_scientific" in st .session_state :
119+ # Find the display name for this scientific name
120+ for i , display_name in enumerate (display_names ):
121+ if (
122+ species_display_map [display_name ]
123+ == st .session_state .selected_species_scientific
124+ ):
125+ default_index = i
126+ break
116127
117128 # Only do random selection on very first load
118129 if "species_initialized" not in st .session_state :
@@ -130,8 +141,8 @@ def get_user_selections():
130141 )
131142 selected_species = species_display_map [selected_species_display ]
132143
133- # Store the selected species display name for next rerun
134- st .session_state .selected_species_display = selected_species_display
144+ # Store the scientific name (not display name) for next rerun
145+ st .session_state .selected_species_scientific = selected_species
135146
136147 # Confidence threshold
137148 confidence_threshold = st .sidebar .slider (
0 commit comments