Ilyas KHIAT
commited on
Commit
·
28d07c2
1
Parent(s):
a2b2891
redisp prompts
Browse files- chat_te.py +27 -1
- prompt.py +9 -3
chat_te.py
CHANGED
@@ -62,6 +62,13 @@ def get_response(chain,user_query, chat_history):
|
|
62 |
|
63 |
return chain.stream(question)
|
64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
def display_chat_te():
|
66 |
# app config
|
67 |
st.title("Chatbot")
|
@@ -85,7 +92,26 @@ def display_chat_te():
|
|
85 |
with st.chat_message("Moi"):
|
86 |
st.write(message.content)
|
87 |
|
88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
user_query = st.chat_input("Par ici...")
|
90 |
if user_query is not None and user_query != "":
|
91 |
st.session_state.chat_history_te.append(HumanMessage(content=user_query))
|
|
|
62 |
|
63 |
return chain.stream(question)
|
64 |
|
65 |
+
@st.experimental_dialog("Cast your vote")
|
66 |
+
def vote(item):
|
67 |
+
st.write(f"Why is {item} your favorite?")
|
68 |
+
reason = st.text_input("Because...")
|
69 |
+
if st.button("Submit"):
|
70 |
+
st.rerun()
|
71 |
+
|
72 |
def display_chat_te():
|
73 |
# app config
|
74 |
st.title("Chatbot")
|
|
|
92 |
with st.chat_message("Moi"):
|
93 |
st.write(message.content)
|
94 |
|
95 |
+
style = """
|
96 |
+
<style>
|
97 |
+
.css-ocqkz7 {
|
98 |
+
position: fixed;
|
99 |
+
bottom: 0;
|
100 |
+
width: 50%;
|
101 |
+
justify-content: center;
|
102 |
+
align-items: end;
|
103 |
+
margin-bottom: 0.5rem;
|
104 |
+
}
|
105 |
+
</style>
|
106 |
+
"""
|
107 |
+
# Inject the styling code for both elements
|
108 |
+
# st.markdown(style, unsafe_allow_html=True)
|
109 |
+
|
110 |
+
# # user input
|
111 |
+
# col1 , col2 = st.columns([1,8])
|
112 |
+
# if col1.button("chatbot"):
|
113 |
+
# vote("chatbot")
|
114 |
+
# with col2:
|
115 |
user_query = st.chat_input("Par ici...")
|
116 |
if user_query is not None and user_query != "":
|
117 |
st.session_state.chat_history_te.append(HumanMessage(content=user_query))
|
prompt.py
CHANGED
@@ -12,9 +12,11 @@ def get_prompts_list():
|
|
12 |
if isinstance(prompts, list) and all(isinstance(i, dict) for i in prompts):
|
13 |
# Create a DataFrame
|
14 |
df = pd.DataFrame(prompts)
|
15 |
-
|
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 |
# Extract 'name' from 'context' dictionary
|
19 |
df['context'] = df['context'].apply(lambda x: x.get('name') if isinstance(x, dict) else x)
|
20 |
|
@@ -24,15 +26,19 @@ def get_prompts_list():
|
|
24 |
# Group by 'context'
|
25 |
grouped = df.groupby('context')
|
26 |
|
|
|
|
|
27 |
for name, group in grouped:
|
28 |
st.subheader(name) # Display the context name as a subheader
|
29 |
for i, row in group.iterrows():
|
30 |
col1, col2, col3, col4 = st.columns((1, 2, 2, 1))
|
31 |
-
col1.write(
|
32 |
col2.write(row['name']) # name
|
33 |
col3.write(row['text']) # text
|
|
|
|
|
34 |
button_phold = col4.empty() # create a placeholder
|
35 |
-
do_action = button_phold.button('
|
36 |
if do_action:
|
37 |
prompt_html = prompts[i]['text'].replace('\n', '<br>')
|
38 |
prompt_metadata = extract_metadata(prompts[i])
|
|
|
12 |
if isinstance(prompts, list) and all(isinstance(i, dict) for i in prompts):
|
13 |
# Create a DataFrame
|
14 |
df = pd.DataFrame(prompts)
|
|
|
15 |
# Check if 'name', 'context', and 'text' are in df columns
|
16 |
if 'name' in df.columns and 'context' in df.columns and 'text' in df.columns:
|
17 |
+
# Filter prompts with id_context as 'rse' or 'transition'
|
18 |
+
df = df[df['id_context'].isin(['pour-accelerer-la-demarche-rse', 'pour-accelerer-la-demarche-transition-ecologique'])]
|
19 |
+
|
20 |
# Extract 'name' from 'context' dictionary
|
21 |
df['context'] = df['context'].apply(lambda x: x.get('name') if isinstance(x, dict) else x)
|
22 |
|
|
|
26 |
# Group by 'context'
|
27 |
grouped = df.groupby('context')
|
28 |
|
29 |
+
num = 1
|
30 |
+
|
31 |
for name, group in grouped:
|
32 |
st.subheader(name) # Display the context name as a subheader
|
33 |
for i, row in group.iterrows():
|
34 |
col1, col2, col3, col4 = st.columns((1, 2, 2, 1))
|
35 |
+
col1.write(num) # index
|
36 |
col2.write(row['name']) # name
|
37 |
col3.write(row['text']) # text
|
38 |
+
num += 1
|
39 |
+
|
40 |
button_phold = col4.empty() # create a placeholder
|
41 |
+
do_action = button_phold.button('Voir plus', key=i)
|
42 |
if do_action:
|
43 |
prompt_html = prompts[i]['text'].replace('\n', '<br>')
|
44 |
prompt_metadata = extract_metadata(prompts[i])
|