Ilyas KHIAT
commited on
Commit
·
adf0b51
1
Parent(s):
d486d32
exprt import
Browse files- chat_with_pps.py +55 -6
- partie_prenante_carte.py +2 -2
chat_with_pps.py
CHANGED
|
@@ -12,6 +12,44 @@ from high_chart import test_chart
|
|
| 12 |
from export_doc import export_conversation,convert_pp_to_csv,get_conversation
|
| 13 |
import random
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
load_dotenv()
|
| 17 |
def generate_random_color():
|
|
@@ -120,8 +158,8 @@ def disp_carto_in_chat():
|
|
| 120 |
@st.experimental_dialog("Telecharger",width="small")
|
| 121 |
def dowmload_history():
|
| 122 |
brand_name = st.session_state['Nom de la marque']
|
| 123 |
-
format = st.radio("Choisissez le document à telecharger",["",f"Rapport des parties prenantes
|
| 124 |
-
if format == f"Rapport des parties prenantes
|
| 125 |
with st.spinner("Generation en cours..."):
|
| 126 |
summary = get_response("Donne moi un RESUME de la Conversation", st.session_state.chat_history,format_context(st.session_state['pp_grouped'],st.session_state['Nom de la marque']),st.session_state.model)
|
| 127 |
summary = ''.join(summary)
|
|
@@ -129,12 +167,12 @@ def dowmload_history():
|
|
| 129 |
if pdf:
|
| 130 |
st.download_button("Télécharger le PDF", data=pdf, file_name=f"Cartographie {brand_name}.pdf", mime="application/pdf")
|
| 131 |
|
| 132 |
-
if format == f"DataFrame des parties prenantes
|
| 133 |
csv = convert_pp_to_csv(st.session_state['pp_grouped'])
|
| 134 |
if csv:
|
| 135 |
st.download_button("Télécharger le CSV", data=csv, file_name=f"parties_prenantes {brand_name}.csv", mime="text/csv")
|
| 136 |
|
| 137 |
-
if format == f"historique de conversation
|
| 138 |
conv = get_conversation()
|
| 139 |
if not conv:
|
| 140 |
st.error("Une erreur s'est produite lors de la récupération de l'historique de conversation")
|
|
@@ -145,6 +183,16 @@ def dowmload_history():
|
|
| 145 |
|
| 146 |
if st.button("Fermer"):
|
| 147 |
st.rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
|
| 150 |
|
|
@@ -170,7 +218,7 @@ def display_chat():
|
|
| 170 |
|
| 171 |
#sticky bar at the top
|
| 172 |
header = st.container()
|
| 173 |
-
col1,col2,col3, col4 = header.columns([2,3,2,
|
| 174 |
|
| 175 |
if col1.button("Prompts"):
|
| 176 |
show_prompts()
|
|
@@ -182,7 +230,8 @@ def display_chat():
|
|
| 182 |
if col4.button("Télécharger"):
|
| 183 |
dowmload_history()
|
| 184 |
header.write("""<div class='fixed-header'/>""", unsafe_allow_html=True)
|
| 185 |
-
|
|
|
|
| 186 |
|
| 187 |
# Custom CSS for the sticky header
|
| 188 |
st.markdown(
|
|
|
|
| 12 |
from export_doc import export_conversation,convert_pp_to_csv,get_conversation
|
| 13 |
import random
|
| 14 |
|
| 15 |
+
def parse_conversation(file_content):
|
| 16 |
+
conversation = []
|
| 17 |
+
current_speaker = None
|
| 18 |
+
current_message = []
|
| 19 |
+
|
| 20 |
+
for line in file_content.decode('utf-8').splitlines():
|
| 21 |
+
line = line.strip()
|
| 22 |
+
if line.startswith('AI:'):
|
| 23 |
+
if current_message:
|
| 24 |
+
conversation.append((current_speaker, "\n".join(current_message)))
|
| 25 |
+
current_message = []
|
| 26 |
+
current_speaker = 'AI'
|
| 27 |
+
current_message.append(line[3:].strip())
|
| 28 |
+
elif line.startswith('Moi:'):
|
| 29 |
+
if current_message:
|
| 30 |
+
conversation.append((current_speaker, "\n".join(current_message)))
|
| 31 |
+
current_message = []
|
| 32 |
+
current_speaker = 'Moi'
|
| 33 |
+
current_message.append(line[4:].strip())
|
| 34 |
+
else:
|
| 35 |
+
current_message.append(line)
|
| 36 |
+
|
| 37 |
+
if current_message:
|
| 38 |
+
conversation.append((current_speaker, "\n".join(current_message)))
|
| 39 |
+
|
| 40 |
+
return conversation
|
| 41 |
+
|
| 42 |
+
def convert_to_message_objects(conversation):
|
| 43 |
+
message_objects = []
|
| 44 |
+
for speaker, message in conversation:
|
| 45 |
+
if speaker == 'AI':
|
| 46 |
+
message_objects.append(AIMessage(content=message))
|
| 47 |
+
elif speaker == 'Moi':
|
| 48 |
+
message_objects.append(HumanMessage(content=message))
|
| 49 |
+
|
| 50 |
+
message_objects.pop(0)
|
| 51 |
+
return message_objects
|
| 52 |
+
|
| 53 |
|
| 54 |
load_dotenv()
|
| 55 |
def generate_random_color():
|
|
|
|
| 158 |
@st.experimental_dialog("Telecharger",width="small")
|
| 159 |
def dowmload_history():
|
| 160 |
brand_name = st.session_state['Nom de la marque']
|
| 161 |
+
format = st.radio("Choisissez le document à telecharger",["",f"Rapport des parties prenantes (PDF)",f"DataFrame des parties prenantes (CSV)",f"historique de conversation (Fichier Texte)"])
|
| 162 |
+
if format == f"Rapport des parties prenantes (PDF)":
|
| 163 |
with st.spinner("Generation en cours..."):
|
| 164 |
summary = get_response("Donne moi un RESUME de la Conversation", st.session_state.chat_history,format_context(st.session_state['pp_grouped'],st.session_state['Nom de la marque']),st.session_state.model)
|
| 165 |
summary = ''.join(summary)
|
|
|
|
| 167 |
if pdf:
|
| 168 |
st.download_button("Télécharger le PDF", data=pdf, file_name=f"Cartographie {brand_name}.pdf", mime="application/pdf")
|
| 169 |
|
| 170 |
+
if format == f"DataFrame des parties prenantes (CSV)":
|
| 171 |
csv = convert_pp_to_csv(st.session_state['pp_grouped'])
|
| 172 |
if csv:
|
| 173 |
st.download_button("Télécharger le CSV", data=csv, file_name=f"parties_prenantes {brand_name}.csv", mime="text/csv")
|
| 174 |
|
| 175 |
+
if format == f"historique de conversation (Fichier Texte)":
|
| 176 |
conv = get_conversation()
|
| 177 |
if not conv:
|
| 178 |
st.error("Une erreur s'est produite lors de la récupération de l'historique de conversation")
|
|
|
|
| 183 |
|
| 184 |
if st.button("Fermer"):
|
| 185 |
st.rerun()
|
| 186 |
+
|
| 187 |
+
@st.experimental_dialog("Importer",width="small")
|
| 188 |
+
def import_conversation():
|
| 189 |
+
uploaded_file = st.file_uploader("Choisissez un fichier texte", type=["txt"])
|
| 190 |
+
if uploaded_file is not None:
|
| 191 |
+
file_content = uploaded_file.read()
|
| 192 |
+
conversation = parse_conversation(file_content)
|
| 193 |
+
message_object = convert_to_message_objects(conversation)
|
| 194 |
+
st.session_state.chat_history.extend(message_object)
|
| 195 |
+
st.experimental_rerun()
|
| 196 |
|
| 197 |
|
| 198 |
|
|
|
|
| 218 |
|
| 219 |
#sticky bar at the top
|
| 220 |
header = st.container()
|
| 221 |
+
col1,col2,col3, col4,col5,col6 = header.columns([2,3,2,3,2,1])
|
| 222 |
|
| 223 |
if col1.button("Prompts"):
|
| 224 |
show_prompts()
|
|
|
|
| 230 |
if col4.button("Télécharger"):
|
| 231 |
dowmload_history()
|
| 232 |
header.write("""<div class='fixed-header'/>""", unsafe_allow_html=True)
|
| 233 |
+
if col5.button("Importer"):
|
| 234 |
+
import_conversation()
|
| 235 |
|
| 236 |
# Custom CSS for the sticky header
|
| 237 |
st.markdown(
|
partie_prenante_carte.py
CHANGED
|
@@ -327,7 +327,7 @@ def display_pp():
|
|
| 327 |
brand_name = st.text_input("Nom de la marque", st.session_state["Nom de la marque"])
|
| 328 |
st.session_state["Nom de la marque"] = brand_name
|
| 329 |
|
| 330 |
-
option = st.radio("Source", ("A partir de votre site web", "A partir de vos documents entreprise","A partir de
|
| 331 |
|
| 332 |
#if the user chooses to extract from website
|
| 333 |
if option == "A partir de votre site web":
|
|
@@ -400,7 +400,7 @@ def display_pp():
|
|
| 400 |
|
| 401 |
# disp_vertical_slider(partie_prenante)
|
| 402 |
# st.altair_chart(c, use_container_width=True)
|
| 403 |
-
if option == "A partir de
|
| 404 |
uploaded_file = st.file_uploader("Télécharger le fichier CSV", type="csv")
|
| 405 |
if uploaded_file is not None:
|
| 406 |
load_csv(uploaded_file)
|
|
|
|
| 327 |
brand_name = st.text_input("Nom de la marque", st.session_state["Nom de la marque"])
|
| 328 |
st.session_state["Nom de la marque"] = brand_name
|
| 329 |
|
| 330 |
+
option = st.radio("Source", ("A partir de votre site web", "A partir de vos documents entreprise","A partir de fichier interieur (CSV)"))
|
| 331 |
|
| 332 |
#if the user chooses to extract from website
|
| 333 |
if option == "A partir de votre site web":
|
|
|
|
| 400 |
|
| 401 |
# disp_vertical_slider(partie_prenante)
|
| 402 |
# st.altair_chart(c, use_container_width=True)
|
| 403 |
+
if option == "A partir de fichier interieur (CSV)":
|
| 404 |
uploaded_file = st.file_uploader("Télécharger le fichier CSV", type="csv")
|
| 405 |
if uploaded_file is not None:
|
| 406 |
load_csv(uploaded_file)
|