[email protected] commited on
Commit
a9a644b
·
1 Parent(s): b10792b

feat: Enhance chapter parameters with dynamic text area updates

Browse files

- Implemented area_change function to update prompt_system in session state.
- Modified text area to use dynamic keys and on_change functionality for better interactivity.
- Updated tab titles to reflect chapter titles instead of names.

Files changed (1) hide show
  1. pages/chapter_params.py +24 -8
pages/chapter_params.py CHANGED
@@ -1,20 +1,36 @@
1
  import streamlit as st
2
- from util import getYamlConfig
 
 
 
 
 
 
 
 
 
3
 
4
  def page():
5
  st.subheader("Définissez vos paramètres")
6
-
7
- # Charge la configuration YAML
8
- config = getYamlConfig()
9
 
10
- parts = config["chapters"]
11
- parts_sorted = sorted(parts, key=lambda part: part.get('num', float('inf')))
 
 
 
12
 
13
  # Création de tabs pour chaque 'part' trié
14
- tabs = st.tabs([part['name'] for part in parts_sorted])
15
  for part, tab in zip(parts_sorted, tabs):
16
  with tab:
17
- st.text_area("Prompt System", part['prompt_system'], height=400)
 
 
 
 
 
 
 
18
 
19
 
20
  page()
 
1
  import streamlit as st
2
+
3
+ def area_change(key, ):
4
+ new_value = st.session_state[key]
5
+
6
+ key = key[5:]
7
+ chapter_key = f"chapter_{key}"
8
+
9
+ if chapter_key in st.session_state:
10
+ st.session_state[chapter_key]["prompt_system"] = new_value
11
+
12
 
13
  def page():
14
  st.subheader("Définissez vos paramètres")
 
 
 
15
 
16
+ chapters = []
17
+ for chapter in st.session_state["chapters"]:
18
+ chapters.append(st.session_state[f"chapter_{chapter['num']}"])
19
+
20
+ parts_sorted = sorted(chapters, key=lambda part: part.get('num', float('inf')))
21
 
22
  # Création de tabs pour chaque 'part' trié
23
+ tabs = st.tabs([part['title'] for part in parts_sorted])
24
  for part, tab in zip(parts_sorted, tabs):
25
  with tab:
26
+ k = f"area_{part["num"]}"
27
+ st.text_area(
28
+ "Prompt System",
29
+ part['prompt_system'],
30
+ key=k,
31
+ on_change=area_change,
32
+ args=(k,),
33
+ height=400)
34
 
35
 
36
  page()