Spaces:
Sleeping
Sleeping
Commit ·
cdb09ca
1
Parent(s): 8c14cf4
Make See in Code button always visible
Browse filesGenerates code from current parameters when results aren't available yet,
allowing users to see reproducibility code before running classification.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1607 unmodified lines16081609161016111612161316141615161616171618161916201621162216231607 unmodified linesst.rerun()with col_code:if st.session_state.results:if st.button("See in Code", use_container_width=True):st.session_state.show_code_modal = True# Code modal/dialogif st.session_state.get('show_code_modal') and st.session_state.results:st.markdown("---")st.markdown("### Reproducibility Code")st.markdown("Use this code to reproduce the classification with the CatLLM Python package:")st.code(st.session_state.results['code'], language='python')if st.button("Close"):st.session_state.show_code_modal = Falsest.rerun()1607 unmodified lines16081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831607 unmodified linesst.rerun()with col_code:if st.button("See in Code", use_container_width=True):st.session_state.show_code_modal = True# Code modal/dialogif st.session_state.get('show_code_modal'):st.markdown("---")st.markdown("### Reproducibility Code")st.markdown("Use this code to reproduce the classification with the CatLLM Python package:")# Use results code if available, otherwise generate from current parametersif st.session_state.results:code_to_show = st.session_state.results['code']else:# Get current categories from session statecurrent_categories = [c for c in st.session_state.categories[:st.session_state.category_count] if c.strip()]# Determine current input type and descriptioninput_type_map = {"Survey Responses": "text", "PDF Documents": "pdf", "Images": "image"}current_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 = Noneif current_input_type == "pdf":mode_mapping = {"Image (visual documents)": "image","Text (text-heavy)": "text","Both (comprehensive)": "both"}current_mode = mode_mapping.get(st.session_state.get('pdf_mode', 'Image (visual documents)'), 'image')if 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 catllm# Define your categoriescategories = ["Category 1","Category 2",# Add more categories...]# Classify your dataresult = catllm.classify(input_data=df["your_column"].tolist(),categories=categories,api_key="YOUR_API_KEY",description="your_description",user_model="gpt-4o-mini")# View resultsprint(result)result.to_csv("classified_results.csv", index=False)'''st.code(code_to_show, language='python')if st.button("Close"):st.session_state.show_code_modal = Falsest.rerun()
app.py+65-5