cdupland commited on
Commit
68aa090
·
1 Parent(s): cee0ff2

chore: Refactor get_prompts_list function to improve readability and user experience

Browse files
Files changed (1) hide show
  1. prompt.py +33 -28
prompt.py CHANGED
@@ -16,7 +16,13 @@ def get_prompts_list():
16
  # Check if 'name', 'context', and 'text' are in df columns
17
  if 'name' in df.columns and 'context' in df.columns and 'text' in df.columns:
18
  # Filter prompts with id_context as 'rse' or 'transition'
19
- df = df[df['id_context'].isin(['pour-accelerer-la-demarche-rse', 'pour-accelerer-la-demarche-transition-ecologique','ressources-humaines'])]
 
 
 
 
 
 
20
 
21
  # Extract 'name' from 'context' dictionary
22
  df['context'] = df['context'].apply(lambda x: x.get('name') if isinstance(x, dict) else x)
@@ -27,36 +33,35 @@ def get_prompts_list():
27
  # Group by 'context'
28
  grouped = df.groupby('context')
29
 
30
- num = 1
31
 
32
  for name, group in grouped:
33
- st.subheader(name) # Display the context name as a subheader
34
- for i, row in group.iterrows():
35
- col1, col2, col3, col4 = st.columns((1, 2, 2, 2))
36
- col1.write(num) # index
37
- col2.write(row['name']) # name
38
- col3.write(row['text']) # text
39
- num += 1
40
-
41
- button_phold = col4.empty() # create a placeholder
42
- but1, but2 = button_phold.columns(2)
43
-
44
- do_action = but1.button('Voir plus', key=f"v{i}")
45
- execute = but2.button('Executer', key=f"e{i}")
46
- if execute:
47
- st.session_state.chat_history.append(HumanMessage(content=prompts[i]['text']))
48
- return 1
49
- if do_action:
50
- prompt_html = prompts[i]['text'].replace('\n', '<br>')
51
- prompt_metadata = extract_metadata(prompts[i])
52
 
53
- for text in prompt_metadata:
54
- prompt_html = prompt_html.replace(f"{text}", f"<span style='font-weight:bold'>{text}</span>")
55
-
56
- st.html(prompt_html)
57
- i
58
- # Display the full text
59
- # remove button
 
 
 
 
 
 
 
60
  else:
61
  st.write("Data does not contain 'name', 'context', and 'text' fields.")
62
  else:
 
16
  # Check if 'name', 'context', and 'text' are in df columns
17
  if 'name' in df.columns and 'context' in df.columns and 'text' in df.columns:
18
  # Filter prompts with id_context as 'rse' or 'transition'
19
+ df = df[df['id_context'].isin([
20
+ 'identifier-parties-prenantes-organisation',
21
+ 'animer-parties-prenantes-organisation',
22
+ 'pour-accelerer-la-demarche-rse',
23
+ 'pour-accelerer-la-demarche-transition-ecologique',
24
+ 'ressources-humaines'
25
+ ])]
26
 
27
  # Extract 'name' from 'context' dictionary
28
  df['context'] = df['context'].apply(lambda x: x.get('name') if isinstance(x, dict) else x)
 
33
  # Group by 'context'
34
  grouped = df.groupby('context')
35
 
 
36
 
37
  for name, group in grouped:
38
+ num = 1
39
+
40
+ with st.expander(name):
41
+ for i, row in group.iterrows():
42
+ col1, col3, col4 = st.columns((0.4, 4, 2))
43
+ col1.write(num) # index
44
+ # col2.write(row['name']) # name
45
+ col3.write(row['text']) # text
46
+ num += 1
47
+
48
+ button_phold = col4.empty() # create a placeholder
49
+ but1, but2 = button_phold.columns(2)
 
 
 
 
 
 
 
50
 
51
+ do_action = but1.button('Voir plus', key=f"v{i}")
52
+ execute = but2.button('Executer', key=f"e{i}")
53
+ if execute:
54
+ st.session_state.chat_history.append(HumanMessage(content=prompts[i]['text']))
55
+ return 1
56
+ if do_action:
57
+ prompt_html = prompts[i]['text'].replace('\n', '<br>')
58
+ prompt_metadata = extract_metadata(prompts[i])
59
+
60
+ for text in prompt_metadata:
61
+ prompt_html = prompt_html.replace(f"{text}", f"<span style='font-weight:bold'>{text}</span>")
62
+
63
+ st.html(prompt_html)
64
+
65
  else:
66
  st.write("Data does not contain 'name', 'context', and 'text' fields.")
67
  else: