Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import random | |
| import time | |
| def run_symbol_match(): | |
| st.subheader("🧠 Symbol Match Task") | |
| # Step 1: Define symbols and labels | |
| symbols = ['@', '#', '$', '%', '&', '*'] | |
| label_map = { | |
| '@': 'Symbol: @', | |
| '#': 'Symbol: #', | |
| '$': 'Symbol: $', | |
| '%': 'Symbol: %', | |
| '&': 'Symbol: &', | |
| '*': 'Symbol: *' | |
| } | |
| if "phase" not in st.session_state: | |
| st.session_state.phase = "show" | |
| st.session_state.target_symbol = random.choice(symbols) | |
| st.session_state.start_time = None | |
| st.session_state.reaction_time = None | |
| if st.session_state.phase == "show": | |
| st.write("Memorize this symbol:") | |
| st.markdown(f"<h1 style='text-align: center;'>{st.session_state.target_symbol}</h1>", unsafe_allow_html=True) | |
| if st.button("I saw it"): | |
| st.session_state.phase = "match" | |
| st.session_state.start_time = time.time() | |
| st.rerun() | |
| elif st.session_state.phase == "match": | |
| st.write("Pick the symbol you just saw:") | |
| # Build list of tuples: (label, actual value) | |
| options = [(label_map[s], s) for s in symbols] | |
| choice = st.radio("Options:", options, format_func=lambda x: x[0]) | |
| if st.button("Submit"): | |
| end = time.time() | |
| st.session_state.reaction_time = round(end - st.session_state.start_time, 2) | |
| selected_symbol = choice[1] | |
| if selected_symbol == st.session_state.target_symbol: | |
| st.success(f"✅ Correct! Reaction time: {st.session_state.reaction_time}s") | |
| else: | |
| st.error(f"❌ Incorrect. It was {st.session_state.target_symbol}") | |
| st.session_state.phase = "done" | |
| elif st.session_state.phase == "done": | |
| if st.button("Try Again"): | |
| st.session_state.phase = "show" | |
| st.session_state.target_symbol = random.choice(symbols) | |
| st.session_state.start_time = None | |
| st.session_state.reaction_time = None | |
| st.rerun() | |