Acasset45654 commited on
Commit
ef21fb6
·
verified ·
1 Parent(s): 70fba3b

Update refApp.py

Browse files
Files changed (1) hide show
  1. refApp.py +82 -96
refApp.py CHANGED
@@ -1295,86 +1295,81 @@ elif st.session_state.view_mode == "generator":
1295
  if not isinstance(variables_for_form, list):
1296
  variables_for_form = []
1297
 
1298
- cols_per_row = 2 if len(variables_for_form) > 1 else 1
1299
- var_chunks = [variables_for_form[i:i + cols_per_row] for i in range(0, len(variables_for_form), cols_per_row)]
1300
-
1301
- for chunk in var_chunks:
1302
- cols = st.columns(len(chunk))
1303
- for i, var_info in enumerate(chunk):
1304
- with cols[i]:
1305
- widget_key = f"gen_input_{generator_family}_{generator_use_case}_{var_info['name']}"
1306
- field_default = var_info.get("default")
1307
- var_type = var_info.get("type")
1308
-
1309
- if var_type == "text_input":
1310
- gen_form_values[var_info["name"]] = st.text_input(
1311
- var_info["label"],
1312
- value=str(field_default or ""),
1313
- key=widget_key
1314
- )
1315
- elif var_type == "selectbox":
1316
- opts = var_info.get("options", [])
1317
  idx = 0
1318
- if opts:
1319
- try:
1320
- idx = opts.index(field_default) if field_default in opts else 0
1321
- except ValueError:
1322
- idx = 0
1323
- gen_form_values[var_info["name"]] = st.selectbox(
1324
- var_info["label"],
1325
- options=opts,
1326
- index=idx,
1327
- key=widget_key
1328
- )
1329
- elif var_type == "date_input":
1330
- val_date = field_default if isinstance(field_default, date) else datetime.now().date()
1331
- gen_form_values[var_info["name"]] = st.date_input(
1332
- var_info["label"],
1333
- value=val_date,
1334
- key=widget_key
1335
- )
1336
- elif var_type == "number_input":
1337
- current_value_default_gen = var_info.get("default")
1338
- min_val_config_gen = var_info.get("min_value")
1339
- max_val_config_gen = var_info.get("max_value")
1340
- step_config_gen = var_info.get("step")
1341
- val_num_gen = float(current_value_default_gen) if isinstance(current_value_default_gen, (int, float)) else 0.0
1342
- min_val_gen = float(min_val_config_gen) if min_val_config_gen is not None else None
1343
- max_val_gen = float(max_val_config_gen) if max_val_config_gen is not None else None
1344
- step_val_gen = float(step_config_gen) if step_config_gen is not None else 1.0
1345
- if min_val_gen is not None and val_num_gen < min_val_gen:
1346
- val_num_gen = min_val_gen
1347
- if max_val_gen is not None and val_num_gen > max_val_gen:
1348
- val_num_gen = max_val_gen
1349
- gen_form_values[var_info["name"]] = st.number_input(
1350
- var_info["label"],
1351
- value=val_num_gen,
1352
- min_value=min_val_gen,
1353
- max_value=max_val_gen,
1354
- step=step_val_gen,
1355
- key=widget_key,
1356
- format="%.2f"
1357
- )
1358
- elif var_type == "text_area":
1359
- height_val = var_info.get("height")
1360
- final_height = None
1361
- if height_val is not None:
1362
- try:
1363
- h = int(height_val)
1364
- if h >= 68:
1365
- final_height = h
1366
- else:
1367
- final_height = 68
1368
- except (ValueError, TypeError):
1369
- final_height = None
1370
  else:
1371
- final_height = None
1372
- gen_form_values[var_info["name"]] = st.text_area(
1373
- var_info["label"],
1374
- value=str(field_default or ""),
1375
- height=final_height,
1376
- key=widget_key
1377
- )
 
 
 
 
1378
 
1379
  if st.form_submit_button("🚀 Générer Prompt"):
1380
  processed_values_for_template = {}
@@ -1429,25 +1424,20 @@ elif st.session_state.view_mode == "generator":
1429
  key=f"editable_generated_prompt_output_{generator_family}_{generator_use_case}",
1430
  label_visibility="collapsed"
1431
  )
1432
- if edited_prompt_value != st.session_state.active_generated_prompt:
1433
- st.session_state.active_generated_prompt = edited_prompt_value
1434
 
1435
- col_caption, col_indicator = st.columns([1.8, 0.2])
1436
- with col_caption:
1437
- st.caption("Prompt généré (pour relecture et copie manuelle) :")
1438
- with col_indicator:
1439
- st.markdown("<div style='color:red; text-align:right; font-size:0.9em; padding-right:0.9em;'>Copier ici : 👇</div>", unsafe_allow_html=True)
1440
 
1441
  if st.session_state.active_generated_prompt:
1442
- st.code(st.session_state.active_generated_prompt, language='markdown', line_numbers=True)
1443
  else:
1444
  st.markdown("*Aucun prompt généré à afficher.*")
1445
 
1446
- # ⚙️ Paramétrage du Prompt - Configuration Feature (Generator Mode)
1447
- should_expand_config = SHOW_CONFIG_SECTION and st.session_state.get('go_to_config_section', False)
1448
- if SHOW_CONFIG_SECTION:
1449
- with st.expander(f"⚙️ Paramétrage du Prompt: {generator_use_case}", expanded=should_expand_config):
1450
- st.subheader("Template du Prompt")
1451
  safe_family_key_part = str(generator_family).replace(' ', '_').replace('.', '_').replace('{', '_').replace('}', '_').replace('(', '_').replace(')', '_')
1452
  safe_uc_key_part = str(generator_use_case).replace(' ', '_').replace('.', '_').replace('{', '_').replace('}', '_').replace('(', '_').replace(')', '_')
1453
  template_text_area_key = f"template_text_area_{safe_family_key_part}_{safe_uc_key_part}"; new_tpl = st.text_area("Template:", value=current_prompt_config.get('template', ''), height=200, key=template_text_area_key)
@@ -1909,11 +1899,7 @@ elif st.session_state.view_mode == "assistant_creation": # Cette vue gère maint
1909
 
1910
  # Affichage commun du méta-prompt généré (qu'il vienne de la création ou de l'amélioration)
1911
  if st.session_state.generated_meta_prompt_for_llm:
1912
- col_subheader_assist, col_indicator_assist = st.columns([0.85, 0.15])
1913
- with col_subheader_assist:
1914
- st.subheader("📋 Instruction Générée (à coller dans votre LLM) :")
1915
- with col_indicator_assist:
1916
- st.markdown("<div style='color:red; text-align:right; font-size:0.9em; padding-top:1.9em;padding-right:0.9em;'>Copier ici : 👇</div>", unsafe_allow_html=True)
1917
 
1918
  st.code(st.session_state.generated_meta_prompt_for_llm, language='markdown', line_numbers=True)
1919
  st.caption("<span style='color:gray; font-size:0.9em;'>Utilisez l'icône en haut à droite du bloc de code pour copier l'instruction.</span>", unsafe_allow_html=True)
 
1295
  if not isinstance(variables_for_form, list):
1296
  variables_for_form = []
1297
 
1298
+ # Simplified layout to prevent glitch - removed dynamic columns
1299
+ for var_info in variables_for_form:
1300
+ widget_key = f"gen_input_{generator_family}_{generator_use_case}_{var_info['name']}"
1301
+ field_default = var_info.get("default")
1302
+ var_type = var_info.get("type")
1303
+
1304
+ if var_type == "text_input":
1305
+ gen_form_values[var_info["name"]] = st.text_input(
1306
+ var_info["label"],
1307
+ value=str(field_default or ""),
1308
+ key=widget_key
1309
+ )
1310
+ elif var_type == "selectbox":
1311
+ opts = var_info.get("options", [])
1312
+ idx = 0
1313
+ if opts:
1314
+ try:
1315
+ idx = opts.index(field_default) if field_default in opts else 0
1316
+ except ValueError:
1317
  idx = 0
1318
+ gen_form_values[var_info["name"]] = st.selectbox(
1319
+ var_info["label"],
1320
+ options=opts,
1321
+ index=idx,
1322
+ key=widget_key
1323
+ )
1324
+ elif var_type == "date_input":
1325
+ val_date = field_default if isinstance(field_default, date) else datetime.now().date()
1326
+ gen_form_values[var_info["name"]] = st.date_input(
1327
+ var_info["label"],
1328
+ value=val_date,
1329
+ key=widget_key
1330
+ )
1331
+ elif var_type == "number_input":
1332
+ current_value_default_gen = var_info.get("default")
1333
+ min_val_config_gen = var_info.get("min_value")
1334
+ max_val_config_gen = var_info.get("max_value")
1335
+ step_config_gen = var_info.get("step")
1336
+ val_num_gen = float(current_value_default_gen) if isinstance(current_value_default_gen, (int, float)) else 0.0
1337
+ min_val_gen = float(min_val_config_gen) if min_val_config_gen is not None else None
1338
+ max_val_gen = float(max_val_config_gen) if max_val_config_gen is not None else None
1339
+ step_val_gen = float(step_config_gen) if step_config_gen is not None else 1.0
1340
+ if min_val_gen is not None and val_num_gen < min_val_gen:
1341
+ val_num_gen = min_val_gen
1342
+ if max_val_gen is not None and val_num_gen > max_val_gen:
1343
+ val_num_gen = max_val_gen
1344
+ gen_form_values[var_info["name"]] = st.number_input(
1345
+ var_info["label"],
1346
+ value=val_num_gen,
1347
+ min_value=min_val_gen,
1348
+ max_value=max_val_gen,
1349
+ step=step_val_gen,
1350
+ key=widget_key,
1351
+ format="%.2f"
1352
+ )
1353
+ elif var_type == "text_area":
1354
+ height_val = var_info.get("height")
1355
+ final_height = None
1356
+ if height_val is not None:
1357
+ try:
1358
+ h = int(height_val)
1359
+ if h >= 68:
1360
+ final_height = h
 
 
 
 
 
 
 
 
 
1361
  else:
1362
+ final_height = 68
1363
+ except (ValueError, TypeError):
1364
+ final_height = None
1365
+ else:
1366
+ final_height = None
1367
+ gen_form_values[var_info["name"]] = st.text_area(
1368
+ var_info["label"],
1369
+ value=str(field_default or ""),
1370
+ height=final_height,
1371
+ key=widget_key
1372
+ )
1373
 
1374
  if st.form_submit_button("🚀 Générer Prompt"):
1375
  processed_values_for_template = {}
 
1424
  key=f"editable_generated_prompt_output_{generator_family}_{generator_use_case}",
1425
  label_visibility="collapsed"
1426
  )
1427
+ # Removed session state update to prevent auto-restart loop
 
1428
 
1429
+ st.caption("Prompt généré (pour relecture et copie manuelle) - Utilisez l'icône de copie en haut à droite du bloc :")
 
 
 
 
1430
 
1431
  if st.session_state.active_generated_prompt:
1432
+ st.code(st.session_state.active_generated_prompt, language='markdown', line_numbers=False)
1433
  else:
1434
  st.markdown("*Aucun prompt généré à afficher.*")
1435
 
1436
+ # ⚙️ Paramétrage du Prompt - Configuration Feature (Generator Mode) - COMMENTED OUT TO TEST GLITCH
1437
+ # should_expand_config = SHOW_CONFIG_SECTION and st.session_state.get('go_to_config_section', False)
1438
+ # if SHOW_CONFIG_SECTION:
1439
+ # with st.expander(f"⚙️ Paramétrage du Prompt: {generator_use_case}", expanded=should_expand_config):
1440
+ # st.subheader("Template du Prompt")
1441
  safe_family_key_part = str(generator_family).replace(' ', '_').replace('.', '_').replace('{', '_').replace('}', '_').replace('(', '_').replace(')', '_')
1442
  safe_uc_key_part = str(generator_use_case).replace(' ', '_').replace('.', '_').replace('{', '_').replace('}', '_').replace('(', '_').replace(')', '_')
1443
  template_text_area_key = f"template_text_area_{safe_family_key_part}_{safe_uc_key_part}"; new_tpl = st.text_area("Template:", value=current_prompt_config.get('template', ''), height=200, key=template_text_area_key)
 
1899
 
1900
  # Affichage commun du méta-prompt généré (qu'il vienne de la création ou de l'amélioration)
1901
  if st.session_state.generated_meta_prompt_for_llm:
1902
+ st.subheader("📋 Instruction Générée (à coller dans votre LLM) :")
 
 
 
 
1903
 
1904
  st.code(st.session_state.generated_meta_prompt_for_llm, language='markdown', line_numbers=True)
1905
  st.caption("<span style='color:gray; font-size:0.9em;'>Utilisez l'icône en haut à droite du bloc de code pour copier l'instruction.</span>", unsafe_allow_html=True)