import streamlit as st from streamlit_option_menu import option_menu import os import sys import base64 from pathlib import Path # Import the page modules. from attribution_analysis.attribution_analysis_page import show_attribution_analysis from function_vectors.function_vectors_page import show_function_vectors_page from circuit_analysis.circuit_trace_page import show_circuit_trace_page from utilities.welcome_page import show_welcome_page from utilities.utils import set_seed from utilities.localization import initialize_localization, tr, language_selector from utilities.feedback_survey import get_next_participant_id # Import functions with persisted cache to clear them when needed. from attribution_analysis.attribution_analysis_page import ( get_influential_docs, _cached_explain_heatmap as attr_explain_heatmap, generate_all_attribution_analyses ) from circuit_analysis.circuit_trace_page import explain_circuit_visualization from function_vectors.function_vectors_page import ( _perform_analysis as fv_perform_analysis, _explain_with_llm as fv_explain_llm ) # Set the page configuration. st.set_page_config( page_title="LLM Analysis Suite", page_icon="🧠", layout="wide", initial_sidebar_state="expanded" ) # Set TOKENIZERS_PARALLELISM to false to avoid warnings. os.environ["TOKENIZERS_PARALLELISM"] = "false" # Suppress a harmless error on macOS. os.environ["OBJC_DISABLE_INITIALIZE_FORK_SAFETY"] = "YES" # Custom CSS for styling the app. st.markdown(""" """, unsafe_allow_html=True) def main(): # Main function to run the app. set_seed() initialize_localization() # The language selector is now on the welcome page. # We don't need it in the sidebar of the main app. # Check if the user has submitted the welcome form. if "user_info" not in st.session_state or not st.session_state.user_info.get("form_submitted"): show_welcome_page() else: # If the form is submitted, show the main application. # Assign a participant ID if one doesn't exist. if 'participant_id' not in st.session_state: st.session_state.participant_id = get_next_participant_id() # Initialize session state for feedback forms. if 'attr_feedback_submitted' not in st.session_state: st.session_state.attr_feedback_submitted = False if 'fv_feedback_submitted' not in st.session_state: st.session_state.fv_feedback_submitted = False logo_path = Path(__file__).parent / "LOGO" / "Logo.png" if logo_path.exists(): with open(logo_path, "rb") as logo_file: logo_base64 = base64.b64encode(logo_file.read()).decode("utf-8") st.markdown( f"""