Spaces:
Sleeping
Sleeping
Commit ·
2534871
1
Parent(s): 6bb5e51
Replace consensus threshold slider with clear button options
Browse files- Replace numeric slider with radio buttons: Majority (50%+), Two-Thirds (67%+), Unanimous (100%)
- Pass consensus_threshold to code generation for accurate reproducibility code
- Update "See in Code" modal to reflect current classify mode and consensus settings
- Add inline comment in generated code explaining the threshold
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
257 unmodified lines25825926026126226326444 unmodified lines3093103113123133143151023 unmodified lines1339134013411342134313441345134613471348134913501351135213531354174 unmodified lines1529153015311532153315341535114 unmodified lines165016511652165316541655165616571658165916601661166216638 unmodified lines1672167316741675167616771678257 unmodified lines'''def generate_classify_code(input_type, description, categories, model, model_source, mode=None, classify_mode="Single Model", models_list=None):"""Generate Python code for classification."""categories_str = ",\n ".join([f'"{cat}"' for cat in categories])44 unmodified linesmodels_str = '("gpt-4o", "auto", "YOUR_API_KEY"),\n ("claude-sonnet-4-5-20250929", "auto", "YOUR_API_KEY")'mode_param = f',\n mode="{mode}"' if mode and input_type == "pdf" else ''consensus_param = ',\n consensus_threshold=0.5' if classify_mode == "Ensemble" else ''return f'''import catllm{load_data}1023 unmodified linesapi_key = st.text_input("API Key", type="password", key="classify_api_key")# Ensemble-specific optionsif classify_mode == "Ensemble":consensus_threshold = st.slider("Consensus Threshold",min_value=0.0,max_value=1.0,value=0.5,step=0.1,key="consensus_threshold",help="Minimum agreement ratio needed for consensus (0.5 = majority vote)")if st.button("Categorize Data", type="primary", use_container_width=True):if input_data is None:174 unmodified linescode = generate_classify_code(input_type_selected, description, categories_entered,report_model, report_model_source, mode,classify_mode=classify_mode, models_list=models_list)# Generate methodology report with code included114 unmodified linescurrent_input_type = input_type_map.get(st.session_state.get('input_type_radio', 'Survey Responses'), 'text')current_description = st.session_state.get('survey_column', '') or st.session_state.get('pdf_desc', '') or st.session_state.get('image_desc', '') or 'your_data'# Get current modelif st.session_state.get('classify_model_tier', 'Free Models') == 'Free Models':model_display = st.session_state.get('classify_model', 'GPT-4o Mini')current_model = FREE_MODELS_MAP.get(model_display, 'gpt-4o-mini')else:current_model = st.session_state.get('classify_model_paid', 'gpt-4o-mini')current_model_source = get_model_source(current_model)# Get PDF mode if applicablecurrent_mode = None8 unmodified linesif current_categories:code_to_show = generate_classify_code(current_input_type, current_description, current_categories,current_model, current_model_source, current_mode)else:code_to_show = '''import catllm257 unmodified lines25825926026126226326444 unmodified lines3093103113123133143151023 unmodified lines133913401341134213431344134513461347134813491350135113521353135413551356135713581359174 unmodified lines15341535153615371538153915401541114 unmodified lines165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616878 unmodified lines169616971698169917001701170217031704257 unmodified lines'''def generate_classify_code(input_type, description, categories, model, model_source, mode=None, classify_mode="Single Model", models_list=None, consensus_threshold=0.5):"""Generate Python code for classification."""categories_str = ",\n ".join([f'"{cat}"' for cat in categories])44 unmodified linesmodels_str = '("gpt-4o", "auto", "YOUR_API_KEY"),\n ("claude-sonnet-4-5-20250929", "auto", "YOUR_API_KEY")'mode_param = f',\n mode="{mode}"' if mode and input_type == "pdf" else ''consensus_param = f',\n consensus_threshold={consensus_threshold} # {"Majority" if consensus_threshold == 0.5 else "Two-Thirds" if consensus_threshold == 0.67 else "Unanimous"}' if classify_mode == "Ensemble" else ''return f'''import catllm{load_data}1023 unmodified linesapi_key = st.text_input("API Key", type="password", key="classify_api_key")# Ensemble-specific optionsconsensus_threshold = 0.5 # Defaultif classify_mode == "Ensemble":consensus_options = {"Majority (50%+)": 0.5,"Two-Thirds (67%+)": 0.67,"Unanimous (100%)": 1.0,}consensus_choice = st.radio("Consensus Rule",options=list(consensus_options.keys()),horizontal=True,key="consensus_choice",help="How many models must agree for a category to be marked present")consensus_threshold = consensus_options[consensus_choice]if st.button("Categorize Data", type="primary", use_container_width=True):if input_data is None:174 unmodified linescode = generate_classify_code(input_type_selected, description, categories_entered,report_model, report_model_source, mode,classify_mode=classify_mode, models_list=models_list,consensus_threshold=consensus_threshold)# Generate methodology report with code included114 unmodified linescurrent_input_type = input_type_map.get(st.session_state.get('input_type_radio', 'Survey Responses'), 'text')current_description = st.session_state.get('survey_column', '') or st.session_state.get('pdf_desc', '') or st.session_state.get('image_desc', '') or 'your_data'# Get current classification mode and modelscurrent_classify_mode = st.session_state.get('classify_mode', 'Single Model')current_model_tier = st.session_state.get('classify_model_tier', 'Free Models')if current_classify_mode in ["Model Comparison", "Ensemble"]:# Multi-model modeif current_model_tier == 'Free Models':model_displays = st.session_state.get('classify_models_multi', [])current_models_list = [FREE_MODELS_MAP.get(d, d) for d in model_displays]else:current_models_list = st.session_state.get('classify_models_multi_paid', [])current_model = ", ".join(current_models_list) if current_models_list else "gpt-4o-mini"current_model_source = f"{current_classify_mode} ({len(current_models_list)} models)"else:# Single model modeif current_model_tier == 'Free Models':model_display = st.session_state.get('classify_model', 'GPT-4o Mini')current_model = FREE_MODELS_MAP.get(model_display, 'gpt-4o-mini')else:current_model = st.session_state.get('classify_model_paid', 'gpt-4o-mini')current_models_list = [current_model]current_model_source = get_model_source(current_model)# Get consensus threshold for ensemble modeconsensus_options = {"Majority (50%+)": 0.5, "Two-Thirds (67%+)": 0.67, "Unanimous (100%)": 1.0}current_consensus = consensus_options.get(st.session_state.get('consensus_choice', 'Majority (50%+)'), 0.5)# Get PDF mode if applicablecurrent_mode = None8 unmodified linesif current_categories:code_to_show = generate_classify_code(current_input_type, current_description, current_categories,current_model, current_model_source, current_mode,classify_mode=current_classify_mode, models_list=current_models_list,consensus_threshold=current_consensus)else:code_to_show = '''import catllm
app.py+44-18