cdupland
commited on
Commit
·
68aa090
1
Parent(s):
cee0ff2
chore: Refactor get_prompts_list function to improve readability and user experience
Browse files
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([
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
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 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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:
|