chrissoria commited on
Commit
1195fbd
·
1 Parent(s): 3ef1ec4

Add sidebar: move wordmark, model controls, and reset out of main layout

Browse files
Files changed (1) hide show
  1. app.py +218 -183
app.py CHANGED
@@ -1106,6 +1106,14 @@ st.set_page_config(
1106
  # Same theme as the desktop app and catllm.com (theme.py).
1107
  inject_css()
1108
 
 
 
 
 
 
 
 
 
1109
  # Initialize session state
1110
  if 'categories' not in st.session_state:
1111
  st.session_state.categories = [''] * MAX_CATEGORIES
@@ -1128,12 +1136,16 @@ if 'image_data' not in st.session_state:
1128
  if 'extraction_params' not in st.session_state:
1129
  st.session_state.extraction_params = None # Stores params when categories are auto-extracted
1130
 
1131
- # Wordmark: cat-shield mark + IBM Plex Sans "CatLLM" + mono subtitle.
1132
- render_wordmark("NLP for survey research · UC Berkeley")
 
 
 
 
1133
 
1134
- # About section
1135
- with st.expander("About This App"):
1136
- st.markdown("""
1137
  **Privacy Notice:** Your data is sent to third-party LLM APIs for classification. Do not upload sensitive, confidential, or personally identifiable information (PII).
1138
 
1139
  ---
@@ -1172,7 +1184,200 @@ Soria, C. (2025). CatLLM: A Python package for LLM-based text classification. DO
1172
  ```
1173
  """)
1174
 
1175
- # Main layout
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1176
  col_input, col_output = st.columns([1, 1])
1177
 
1178
  with col_input:
@@ -1330,7 +1535,7 @@ with col_input:
1330
  if auto_mode:
1331
  st.session_state.task_mode = "auto_extract"
1332
 
1333
- # Auto-extract settings
1334
  if st.session_state.task_mode == "auto_extract":
1335
  st.markdown("### Auto-extract Categories")
1336
  st.markdown("We'll analyze your data to discover the main categories.")
@@ -1356,22 +1561,6 @@ with col_input:
1356
  help="Guide the model to prioritize extracting categories related to this focus"
1357
  )
1358
 
1359
- # Model selection for extraction
1360
- st.markdown("### Model Selection")
1361
- model_tier = st.radio(
1362
- "Model Tier",
1363
- options=["Free Models", "Bring Your Own Key"],
1364
- key="extract_model_tier"
1365
- )
1366
-
1367
- if model_tier == "Free Models":
1368
- model_display = st.selectbox("Model", options=FREE_MODEL_DISPLAY_NAMES, key="extract_model")
1369
- model = FREE_MODELS_MAP[model_display] # Convert to actual model name
1370
- api_key = ""
1371
- else:
1372
- model = st.selectbox("Model", options=PAID_MODEL_CHOICES, key="extract_model_paid")
1373
- api_key = st.text_input("API Key", type="password", key="extract_api_key")
1374
-
1375
  if st.button("Extract Categories", type="primary"):
1376
  if input_data is None:
1377
  st.error("Please upload data first")
@@ -1506,142 +1695,6 @@ with col_input:
1506
  st.session_state.category_count += 1
1507
  st.rerun()
1508
 
1509
- st.markdown("### Model Selection")
1510
-
1511
- # Classification mode selector
1512
- classify_mode = st.radio(
1513
- "Classification Mode",
1514
- options=["Single Model", "Model Comparison", "Ensemble"],
1515
- horizontal=True,
1516
- key="classify_mode",
1517
- help="Single: one model. Comparison: see results from multiple models side-by-side. Ensemble: multiple models vote for consensus."
1518
- )
1519
-
1520
- model_tier = st.radio(
1521
- "Model Tier",
1522
- options=["Free Models", "Bring Your Own Key"],
1523
- key="classify_model_tier"
1524
- )
1525
-
1526
- # Multi-model mode uses multiselect
1527
- is_multi_model = classify_mode in ["Model Comparison", "Ensemble"]
1528
- min_models = 3 if classify_mode == "Ensemble" else 2
1529
-
1530
- # Track per-run temperatures: list of (model_name, temperature) for ensemble,
1531
- # or dict {model_name: temperature} for model comparison
1532
- model_temperatures = {}
1533
- # ensemble_runs stores list of (model_name, temperature) allowing duplicate models
1534
- ensemble_runs = []
1535
-
1536
- if classify_mode == "Ensemble":
1537
- # Ensemble mode: dynamic rows allowing same model multiple times with different temps
1538
- if "ensemble_num_runs" not in st.session_state:
1539
- st.session_state.ensemble_num_runs = 3
1540
-
1541
- if model_tier == "Free Models":
1542
- model_options = FREE_MODEL_DISPLAY_NAMES
1543
- is_free = True
1544
- else:
1545
- model_options = PAID_MODEL_CHOICES
1546
- is_free = False
1547
-
1548
- st.markdown(f"**Model Runs** (select {min_models}+ runs)")
1549
- for i in range(st.session_state.ensemble_num_runs):
1550
- cols = st.columns([3, 1, 0.5])
1551
- with cols[0]:
1552
- default_idx = 0 if i < len(model_options) else i % len(model_options)
1553
- selected = st.selectbox(
1554
- f"Run {i+1}", options=model_options,
1555
- index=default_idx, key=f"ensemble_model_{i}",
1556
- label_visibility="collapsed"
1557
- )
1558
- with cols[1]:
1559
- temp = st.number_input(
1560
- "Temp", min_value=0.0, max_value=2.0, value=round(i * 0.25, 2),
1561
- step=0.25, key=f"ensemble_temp_{i}", label_visibility="collapsed"
1562
- )
1563
- with cols[2]:
1564
- if st.session_state.ensemble_num_runs > 3:
1565
- if st.button("✕", key=f"ensemble_remove_{i}"):
1566
- st.session_state.ensemble_num_runs -= 1
1567
- st.rerun()
1568
-
1569
- model_name = FREE_MODELS_MAP[selected] if is_free else selected
1570
- ensemble_runs.append((model_name, temp))
1571
-
1572
- if st.button("Add Run", key="add_ensemble_run"):
1573
- st.session_state.ensemble_num_runs += 1
1574
- st.rerun()
1575
-
1576
- models_list = [r[0] for r in ensemble_runs]
1577
- model_temperatures = {f"{r[0]}__run{i}": r[1] for i, r in enumerate(ensemble_runs)}
1578
- api_key = "" if model_tier == "Free Models" else st.text_input("API Key", type="password", key="classify_api_key")
1579
-
1580
- elif is_multi_model:
1581
- # Model Comparison mode: multiselect (each model unique) + temperature row
1582
- if model_tier == "Free Models":
1583
- default_models = FREE_MODEL_DISPLAY_NAMES[:min_models] if len(FREE_MODEL_DISPLAY_NAMES) >= min_models else FREE_MODEL_DISPLAY_NAMES
1584
- model_displays = st.multiselect(
1585
- f"Models (select {min_models}+)",
1586
- options=FREE_MODEL_DISPLAY_NAMES,
1587
- default=default_models,
1588
- key="classify_models_multi"
1589
- )
1590
- models_list = [FREE_MODELS_MAP[d] for d in model_displays]
1591
- api_key = ""
1592
- else:
1593
- default_models = PAID_MODEL_CHOICES[:min_models] if len(PAID_MODEL_CHOICES) >= min_models else PAID_MODEL_CHOICES
1594
- models_list = st.multiselect(
1595
- f"Models (select {min_models}+)",
1596
- options=PAID_MODEL_CHOICES,
1597
- default=default_models,
1598
- key="classify_models_multi_paid"
1599
- )
1600
- api_key = st.text_input("API Key", type="password", key="classify_api_key")
1601
-
1602
- if models_list:
1603
- st.markdown("**Model Temperature**")
1604
- temp_cols = st.columns(len(models_list))
1605
- for idx, (col, m) in enumerate(zip(temp_cols, models_list)):
1606
- short_name = m.split('/')[-1].split(':')[0][:20]
1607
- model_temperatures[m] = col.number_input(
1608
- short_name,
1609
- min_value=0.0,
1610
- max_value=2.0,
1611
- value=0.0,
1612
- step=0.25,
1613
- key=f"temp_{idx}",
1614
- help=f"Temperature for {m} (0 = deterministic, higher = more creative)"
1615
- )
1616
- else:
1617
- # Single model mode
1618
- if model_tier == "Free Models":
1619
- model_display = st.selectbox("Model", options=FREE_MODEL_DISPLAY_NAMES, key="classify_model")
1620
- model = FREE_MODELS_MAP[model_display] # Convert to actual model name
1621
- models_list = [model]
1622
- api_key = ""
1623
- else:
1624
- model = st.selectbox("Model", options=PAID_MODEL_CHOICES, key="classify_model_paid")
1625
- models_list = [model]
1626
- api_key = st.text_input("API Key", type="password", key="classify_api_key")
1627
-
1628
- # Ensemble-specific options
1629
- consensus_threshold = 0.5 # Default
1630
- if classify_mode == "Ensemble":
1631
- consensus_options = {
1632
- "Majority (50%+)": 0.5,
1633
- "Two-Thirds (67%+)": 0.67,
1634
- "Unanimous (100%)": 1.0,
1635
- }
1636
- consensus_choice = st.radio(
1637
- "Consensus Rule",
1638
- options=list(consensus_options.keys()),
1639
- horizontal=True,
1640
- key="consensus_choice",
1641
- help="How many models must agree for a category to be marked present"
1642
- )
1643
- consensus_threshold = consensus_options[consensus_choice]
1644
-
1645
  if st.button("Categorize Data", type="primary", use_container_width=True):
1646
  if input_data is None:
1647
  st.error("Please upload data first")
@@ -1987,31 +2040,13 @@ with col_output:
1987
  mime="application/pdf"
1988
  )
1989
 
1990
- # Code
1991
  with st.expander("See the Code"):
1992
  st.code(results['code'], language='python')
1993
  else:
1994
  st.info("Upload data, select categories, and click 'Categorize Data' to see results here.")
1995
 
1996
- # Bottom buttons
1997
- col_reset, col_code = st.columns(2)
1998
- with col_reset:
1999
- if st.button("Reset", type="secondary", use_container_width=True):
2000
- st.session_state.categories = [''] * MAX_CATEGORIES
2001
- st.session_state.category_count = INITIAL_CATEGORIES
2002
- st.session_state.task_mode = None
2003
- st.session_state.extracted_categories = None
2004
- st.session_state.extraction_params = None
2005
- st.session_state.results = None
2006
- if hasattr(st.session_state, 'example_loaded'):
2007
- del st.session_state.example_loaded
2008
- st.rerun()
2009
-
2010
- with col_code:
2011
- if st.button("See in Code", use_container_width=True):
2012
- st.session_state.show_code_modal = True
2013
-
2014
- # Code modal/dialog
2015
  if st.session_state.get('show_code_modal'):
2016
  st.markdown("---")
2017
  st.markdown("### Reproducibility Code")
@@ -2069,7 +2104,7 @@ if st.session_state.get('show_code_modal'):
2069
  if current_categories:
2070
  # Check if categories were auto-extracted
2071
  if st.session_state.extraction_params:
2072
- current_temperatures = results.get('model_temperatures', {})
2073
  classify_params = {
2074
  'model': current_model,
2075
  'description': current_description,
@@ -2078,18 +2113,18 @@ if st.session_state.get('show_code_modal'):
2078
  'models_list': current_models_list,
2079
  'consensus_threshold': current_consensus,
2080
  'model_temperatures': current_temperatures,
2081
- 'ensemble_runs': results.get('ensemble_runs'),
2082
  }
2083
  code_to_show = generate_full_code(st.session_state.extraction_params, classify_params)
2084
  else:
2085
- current_temperatures = results.get('model_temperatures', {})
2086
  code_to_show = generate_classify_code(
2087
  current_input_type, current_description, current_categories,
2088
  current_model, current_model_source, current_mode,
2089
  classify_mode=current_classify_mode, models_list=current_models_list,
2090
  consensus_threshold=current_consensus,
2091
  model_temperatures=current_temperatures,
2092
- ensemble_runs=results.get('ensemble_runs'),
2093
  )
2094
  else:
2095
  code_to_show = '''import catllm
 
1106
  # Same theme as the desktop app and catllm.com (theme.py).
1107
  inject_css()
1108
 
1109
+ # Sidebar width CSS
1110
+ st.markdown(
1111
+ """<style>
1112
+ [data-testid="stSidebar"] { min-width: 300px !important; max-width: 300px !important; }
1113
+ </style>""",
1114
+ unsafe_allow_html=True,
1115
+ )
1116
+
1117
  # Initialize session state
1118
  if 'categories' not in st.session_state:
1119
  st.session_state.categories = [''] * MAX_CATEGORIES
 
1136
  if 'extraction_params' not in st.session_state:
1137
  st.session_state.extraction_params = None # Stores params when categories are auto-extracted
1138
 
1139
+ # -----------------------------------------------------------------------
1140
+ # SIDEBAR
1141
+ # -----------------------------------------------------------------------
1142
+ with st.sidebar:
1143
+ # Wordmark: cat-shield mark + IBM Plex Sans "CatLLM" + mono subtitle.
1144
+ render_wordmark("NLP for survey research · UC Berkeley")
1145
 
1146
+ # About section
1147
+ with st.expander("About This App"):
1148
+ st.markdown("""
1149
  **Privacy Notice:** Your data is sent to third-party LLM APIs for classification. Do not upload sensitive, confidential, or personally identifiable information (PII).
1150
 
1151
  ---
 
1184
  ```
1185
  """)
1186
 
1187
+ st.markdown("---")
1188
+
1189
+ # ------------------------------------------------------------------
1190
+ # Classification Mode — only shown when task_mode == "manual"
1191
+ # ------------------------------------------------------------------
1192
+ if st.session_state.task_mode == "manual":
1193
+ classify_mode = st.radio(
1194
+ "Classification Mode",
1195
+ options=["Single Model", "Model Comparison", "Ensemble"],
1196
+ horizontal=False,
1197
+ key="classify_mode",
1198
+ help="Single: one model. Comparison: see results from multiple models side-by-side. Ensemble: multiple models vote for consensus."
1199
+ )
1200
+ else:
1201
+ # Default value when not in manual mode (auto-extract always uses single model)
1202
+ classify_mode = "Single Model"
1203
+
1204
+ # ------------------------------------------------------------------
1205
+ # Model Tier
1206
+ # ------------------------------------------------------------------
1207
+ if st.session_state.task_mode == "auto_extract":
1208
+ model_tier = st.radio(
1209
+ "Model Tier",
1210
+ options=["Free Models", "Bring Your Own Key"],
1211
+ key="extract_model_tier"
1212
+ )
1213
+ else:
1214
+ model_tier = st.radio(
1215
+ "Model Tier",
1216
+ options=["Free Models", "Bring Your Own Key"],
1217
+ key="classify_model_tier"
1218
+ )
1219
+
1220
+ # ------------------------------------------------------------------
1221
+ # Model selection — varies by classify_mode
1222
+ # ------------------------------------------------------------------
1223
+ is_multi_model = classify_mode in ["Model Comparison", "Ensemble"]
1224
+ min_models = 3 if classify_mode == "Ensemble" else 2
1225
+
1226
+ # Track per-run temperatures
1227
+ model_temperatures = {}
1228
+ ensemble_runs = []
1229
+
1230
+ if st.session_state.task_mode == "auto_extract":
1231
+ # Auto-extract: always single model
1232
+ if model_tier == "Free Models":
1233
+ model_display = st.selectbox("Model", options=FREE_MODEL_DISPLAY_NAMES, key="extract_model")
1234
+ model = FREE_MODELS_MAP[model_display]
1235
+ api_key = ""
1236
+ else:
1237
+ model = st.selectbox("Model", options=PAID_MODEL_CHOICES, key="extract_model_paid")
1238
+ api_key = st.text_input("API Key", type="password", key="extract_api_key")
1239
+ models_list = [model]
1240
+
1241
+ elif classify_mode == "Ensemble":
1242
+ # Ensemble mode: dynamic rows allowing same model multiple times with different temps
1243
+ if "ensemble_num_runs" not in st.session_state:
1244
+ st.session_state.ensemble_num_runs = 3
1245
+
1246
+ if model_tier == "Free Models":
1247
+ model_options = FREE_MODEL_DISPLAY_NAMES
1248
+ is_free = True
1249
+ else:
1250
+ model_options = PAID_MODEL_CHOICES
1251
+ is_free = False
1252
+
1253
+ st.markdown(f"**Model Runs** (select {min_models}+ runs)")
1254
+ for i in range(st.session_state.ensemble_num_runs):
1255
+ cols = st.columns([3, 1, 0.5])
1256
+ with cols[0]:
1257
+ default_idx = 0 if i < len(model_options) else i % len(model_options)
1258
+ selected = st.selectbox(
1259
+ f"Run {i+1}", options=model_options,
1260
+ index=default_idx, key=f"ensemble_model_{i}",
1261
+ label_visibility="collapsed"
1262
+ )
1263
+ with cols[1]:
1264
+ temp = st.number_input(
1265
+ "Temp", min_value=0.0, max_value=2.0, value=round(i * 0.25, 2),
1266
+ step=0.25, key=f"ensemble_temp_{i}", label_visibility="collapsed"
1267
+ )
1268
+ with cols[2]:
1269
+ if st.session_state.ensemble_num_runs > 3:
1270
+ if st.button("✕", key=f"ensemble_remove_{i}"):
1271
+ st.session_state.ensemble_num_runs -= 1
1272
+ st.rerun()
1273
+
1274
+ model_name = FREE_MODELS_MAP[selected] if is_free else selected
1275
+ ensemble_runs.append((model_name, temp))
1276
+
1277
+ if st.button("Add Run", key="add_ensemble_run"):
1278
+ st.session_state.ensemble_num_runs += 1
1279
+ st.rerun()
1280
+
1281
+ models_list = [r[0] for r in ensemble_runs]
1282
+ model_temperatures = {f"{r[0]}__run{i}": r[1] for i, r in enumerate(ensemble_runs)}
1283
+ model = models_list[0] if models_list else ""
1284
+ api_key = "" if model_tier == "Free Models" else st.text_input("API Key", type="password", key="classify_api_key")
1285
+
1286
+ elif is_multi_model:
1287
+ # Model Comparison mode: multiselect (each model unique) + temperature row
1288
+ if model_tier == "Free Models":
1289
+ default_models = FREE_MODEL_DISPLAY_NAMES[:min_models] if len(FREE_MODEL_DISPLAY_NAMES) >= min_models else FREE_MODEL_DISPLAY_NAMES
1290
+ model_displays = st.multiselect(
1291
+ f"Models (select {min_models}+)",
1292
+ options=FREE_MODEL_DISPLAY_NAMES,
1293
+ default=default_models,
1294
+ key="classify_models_multi"
1295
+ )
1296
+ models_list = [FREE_MODELS_MAP[d] for d in model_displays]
1297
+ api_key = ""
1298
+ else:
1299
+ default_models = PAID_MODEL_CHOICES[:min_models] if len(PAID_MODEL_CHOICES) >= min_models else PAID_MODEL_CHOICES
1300
+ models_list = st.multiselect(
1301
+ f"Models (select {min_models}+)",
1302
+ options=PAID_MODEL_CHOICES,
1303
+ default=default_models,
1304
+ key="classify_models_multi_paid"
1305
+ )
1306
+ api_key = st.text_input("API Key", type="password", key="classify_api_key")
1307
+
1308
+ if models_list:
1309
+ st.markdown("**Model Temperature**")
1310
+ temp_cols = st.columns(len(models_list))
1311
+ for idx, (col, m) in enumerate(zip(temp_cols, models_list)):
1312
+ short_name = m.split('/')[-1].split(':')[0][:20]
1313
+ model_temperatures[m] = col.number_input(
1314
+ short_name,
1315
+ min_value=0.0,
1316
+ max_value=2.0,
1317
+ value=0.0,
1318
+ step=0.25,
1319
+ key=f"temp_{idx}",
1320
+ help=f"Temperature for {m} (0 = deterministic, higher = more creative)"
1321
+ )
1322
+ model = models_list[0] if models_list else ""
1323
+
1324
+ else:
1325
+ # Single model mode
1326
+ if model_tier == "Free Models":
1327
+ model_display = st.selectbox("Model", options=FREE_MODEL_DISPLAY_NAMES, key="classify_model")
1328
+ model = FREE_MODELS_MAP[model_display]
1329
+ models_list = [model]
1330
+ api_key = ""
1331
+ else:
1332
+ model = st.selectbox("Model", options=PAID_MODEL_CHOICES, key="classify_model_paid")
1333
+ models_list = [model]
1334
+ api_key = st.text_input("API Key", type="password", key="classify_api_key")
1335
+
1336
+ # ------------------------------------------------------------------
1337
+ # Ensemble consensus rule
1338
+ # ------------------------------------------------------------------
1339
+ consensus_threshold = 0.5 # Default
1340
+ if classify_mode == "Ensemble":
1341
+ consensus_options = {
1342
+ "Majority (50%+)": 0.5,
1343
+ "Two-Thirds (67%+)": 0.67,
1344
+ "Unanimous (100%)": 1.0,
1345
+ }
1346
+ consensus_choice = st.radio(
1347
+ "Consensus Rule",
1348
+ options=list(consensus_options.keys()),
1349
+ horizontal=False,
1350
+ key="consensus_choice",
1351
+ help="How many models must agree for a category to be marked present"
1352
+ )
1353
+ consensus_threshold = consensus_options[consensus_choice]
1354
+
1355
+ st.markdown("---")
1356
+
1357
+ # ------------------------------------------------------------------
1358
+ # "See in Code" button — visible only when results exist
1359
+ # ------------------------------------------------------------------
1360
+ if st.session_state.results:
1361
+ if st.button("See in Code", use_container_width=True):
1362
+ st.session_state.show_code_modal = True
1363
+
1364
+ # ------------------------------------------------------------------
1365
+ # Reset button at bottom of sidebar
1366
+ # ------------------------------------------------------------------
1367
+ if st.button("Reset", type="secondary", use_container_width=True):
1368
+ st.session_state.categories = [''] * MAX_CATEGORIES
1369
+ st.session_state.category_count = INITIAL_CATEGORIES
1370
+ st.session_state.task_mode = None
1371
+ st.session_state.extracted_categories = None
1372
+ st.session_state.extraction_params = None
1373
+ st.session_state.results = None
1374
+ if hasattr(st.session_state, 'example_loaded'):
1375
+ del st.session_state.example_loaded
1376
+ st.rerun()
1377
+
1378
+ # -----------------------------------------------------------------------
1379
+ # MAIN AREA — 2-column layout
1380
+ # -----------------------------------------------------------------------
1381
  col_input, col_output = st.columns([1, 1])
1382
 
1383
  with col_input:
 
1535
  if auto_mode:
1536
  st.session_state.task_mode = "auto_extract"
1537
 
1538
+ # Auto-extract settings (data settings stay in col_input; model selection is in sidebar)
1539
  if st.session_state.task_mode == "auto_extract":
1540
  st.markdown("### Auto-extract Categories")
1541
  st.markdown("We'll analyze your data to discover the main categories.")
 
1561
  help="Guide the model to prioritize extracting categories related to this focus"
1562
  )
1563
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1564
  if st.button("Extract Categories", type="primary"):
1565
  if input_data is None:
1566
  st.error("Please upload data first")
 
1695
  st.session_state.category_count += 1
1696
  st.rerun()
1697
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1698
  if st.button("Categorize Data", type="primary", use_container_width=True):
1699
  if input_data is None:
1700
  st.error("Please upload data first")
 
2040
  mime="application/pdf"
2041
  )
2042
 
2043
+ # Code inline expander (always available in results panel)
2044
  with st.expander("See the Code"):
2045
  st.code(results['code'], language='python')
2046
  else:
2047
  st.info("Upload data, select categories, and click 'Categorize Data' to see results here.")
2048
 
2049
+ # Code modal/dialog (triggered from sidebar "See in Code" button)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2050
  if st.session_state.get('show_code_modal'):
2051
  st.markdown("---")
2052
  st.markdown("### Reproducibility Code")
 
2104
  if current_categories:
2105
  # Check if categories were auto-extracted
2106
  if st.session_state.extraction_params:
2107
+ current_temperatures = results.get('model_temperatures', {}) if st.session_state.results else {}
2108
  classify_params = {
2109
  'model': current_model,
2110
  'description': current_description,
 
2113
  'models_list': current_models_list,
2114
  'consensus_threshold': current_consensus,
2115
  'model_temperatures': current_temperatures,
2116
+ 'ensemble_runs': st.session_state.results.get('ensemble_runs') if st.session_state.results else None,
2117
  }
2118
  code_to_show = generate_full_code(st.session_state.extraction_params, classify_params)
2119
  else:
2120
+ current_temperatures = st.session_state.results.get('model_temperatures', {}) if st.session_state.results else {}
2121
  code_to_show = generate_classify_code(
2122
  current_input_type, current_description, current_categories,
2123
  current_model, current_model_source, current_mode,
2124
  classify_mode=current_classify_mode, models_list=current_models_list,
2125
  consensus_threshold=current_consensus,
2126
  model_temperatures=current_temperatures,
2127
+ ensemble_runs=st.session_state.results.get('ensemble_runs') if st.session_state.results else None,
2128
  )
2129
  else:
2130
  code_to_show = '''import catllm