chrissoria Claude Opus 4.5 commited on
Commit
cdb09ca
·
1 Parent(s): 8c14cf4

Make See in Code button always visible

Browse files

Generates 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>

Files changed (1) hide show
  1. app.py +65 -5
app.py CHANGED
@@ -1608,16 +1608,76 @@ with col_reset:
1608
  st.rerun()
1609
 
1610
  with col_code:
1611
- if st.session_state.results:
1612
- if st.button("See in Code", use_container_width=True):
1613
- st.session_state.show_code_modal = True
1614
 
1615
  # Code modal/dialog
1616
- if st.session_state.get('show_code_modal') and st.session_state.results:
1617
  st.markdown("---")
1618
  st.markdown("### Reproducibility Code")
1619
  st.markdown("Use this code to reproduce the classification with the CatLLM Python package:")
1620
- st.code(st.session_state.results['code'], language='python')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1621
  if st.button("Close"):
1622
  st.session_state.show_code_modal = False
1623
  st.rerun()
 
1608
  st.rerun()
1609
 
1610
  with col_code:
1611
+ if st.button("See in Code", use_container_width=True):
1612
+ st.session_state.show_code_modal = True
 
1613
 
1614
  # Code modal/dialog
1615
+ if st.session_state.get('show_code_modal'):
1616
  st.markdown("---")
1617
  st.markdown("### Reproducibility Code")
1618
  st.markdown("Use this code to reproduce the classification with the CatLLM Python package:")
1619
+
1620
+ # Use results code if available, otherwise generate from current parameters
1621
+ if st.session_state.results:
1622
+ code_to_show = st.session_state.results['code']
1623
+ else:
1624
+ # Get current categories from session state
1625
+ current_categories = [c for c in st.session_state.categories[:st.session_state.category_count] if c.strip()]
1626
+
1627
+ # Determine current input type and description
1628
+ input_type_map = {"Survey Responses": "text", "PDF Documents": "pdf", "Images": "image"}
1629
+ current_input_type = input_type_map.get(st.session_state.get('input_type_radio', 'Survey Responses'), 'text')
1630
+ 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'
1631
+
1632
+ # Get current model
1633
+ if st.session_state.get('classify_model_tier', 'Free Models') == 'Free Models':
1634
+ model_display = st.session_state.get('classify_model', 'GPT-4o Mini')
1635
+ current_model = FREE_MODELS_MAP.get(model_display, 'gpt-4o-mini')
1636
+ else:
1637
+ current_model = st.session_state.get('classify_model_paid', 'gpt-4o-mini')
1638
+
1639
+ current_model_source = get_model_source(current_model)
1640
+
1641
+ # Get PDF mode if applicable
1642
+ current_mode = None
1643
+ if current_input_type == "pdf":
1644
+ mode_mapping = {
1645
+ "Image (visual documents)": "image",
1646
+ "Text (text-heavy)": "text",
1647
+ "Both (comprehensive)": "both"
1648
+ }
1649
+ current_mode = mode_mapping.get(st.session_state.get('pdf_mode', 'Image (visual documents)'), 'image')
1650
+
1651
+ if current_categories:
1652
+ code_to_show = generate_classify_code(
1653
+ current_input_type, current_description, current_categories,
1654
+ current_model, current_model_source, current_mode
1655
+ )
1656
+ else:
1657
+ code_to_show = '''import catllm
1658
+
1659
+ # Define your categories
1660
+ categories = [
1661
+ "Category 1",
1662
+ "Category 2",
1663
+ # Add more categories...
1664
+ ]
1665
+
1666
+ # Classify your data
1667
+ result = catllm.classify(
1668
+ input_data=df["your_column"].tolist(),
1669
+ categories=categories,
1670
+ api_key="YOUR_API_KEY",
1671
+ description="your_description",
1672
+ user_model="gpt-4o-mini"
1673
+ )
1674
+
1675
+ # View results
1676
+ print(result)
1677
+ result.to_csv("classified_results.csv", index=False)
1678
+ '''
1679
+
1680
+ st.code(code_to_show, language='python')
1681
  if st.button("Close"):
1682
  st.session_state.show_code_modal = False
1683
  st.rerun()