Spaces:
Running
Running
Ilyas KHIAT
commited on
Commit
·
33ab192
1
Parent(s):
5f96521
enhance
Browse files- audit_page/dialogue_doc.py +29 -12
- audit_page/knowledge_graph.py +7 -0
audit_page/dialogue_doc.py
CHANGED
|
@@ -8,6 +8,7 @@ from utils.kg.construct_kg import get_graph
|
|
| 8 |
from audit_page.knowledge_graph import *
|
| 9 |
import json
|
| 10 |
import clipboard
|
|
|
|
| 11 |
|
| 12 |
def graph_doc_to_json(graph):
|
| 13 |
nodes = []
|
|
@@ -30,9 +31,9 @@ def chat_history_formatter(chat_history):
|
|
| 30 |
formatted_chat = ""
|
| 31 |
for message in chat_history:
|
| 32 |
if isinstance(message, AIMessage):
|
| 33 |
-
formatted_chat += f"AI
|
| 34 |
elif isinstance(message, HumanMessage):
|
| 35 |
-
formatted_chat += f"Human
|
| 36 |
return formatted_chat
|
| 37 |
|
| 38 |
def filter_correspondance(source_list:list[str],ref_dict:dict,reverse=False):
|
|
@@ -43,6 +44,16 @@ def filter_correspondance(source_list:list[str],ref_dict:dict,reverse=False):
|
|
| 43 |
# st.write(source_list)
|
| 44 |
# st.write(ref_dict.keys())
|
| 45 |
return [value for key, value in ref_dict.items() if key.lower().strip() in source_list]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
|
| 48 |
def doc_dialog_main():
|
|
@@ -74,13 +85,19 @@ def doc_dialog_main():
|
|
| 74 |
if "chat_graph_history" not in st.session_state:
|
| 75 |
st.session_state.chat_graph_history = []
|
| 76 |
|
|
|
|
| 77 |
if "radio_choice" not in st.session_state:
|
| 78 |
st.session_state.radio_choice = None
|
|
|
|
|
|
|
| 79 |
|
|
|
|
|
|
|
| 80 |
options = ["compte_rendu","graphe de connaissance"]
|
| 81 |
choice = st.radio("Choisissez une option",options,index=st.session_state.radio_choice,horizontal=True,label_visibility="collapsed")
|
| 82 |
-
if choice:
|
| 83 |
st.session_state.radio_choice = options.index(choice)
|
|
|
|
| 84 |
|
| 85 |
audit = st.session_state.audit_simplified
|
| 86 |
content = st.session_state.audit["content"]
|
|
@@ -186,7 +203,7 @@ def doc_dialog_main():
|
|
| 186 |
# if col_copy_c.button("📋",key="copy_cr_chat"):
|
| 187 |
with st.container(height=50,border=False):
|
| 188 |
chat_formatted = chat_history_formatter(st.session_state.cr_chat_history)
|
| 189 |
-
st_copy_to_clipboard(chat_formatted,key="cp_but_cr_chat")
|
| 190 |
# col_success_c.success("Historique copié !")
|
| 191 |
|
| 192 |
elif choice == "graphe de connaissance":
|
|
@@ -202,7 +219,10 @@ def doc_dialog_main():
|
|
| 202 |
st.session_state.chat_graph_history = []
|
| 203 |
|
| 204 |
node_types = get_node_types(graph[0])
|
| 205 |
-
|
|
|
|
|
|
|
|
|
|
| 206 |
st.session_state.node_types = nodes_type_dict
|
| 207 |
st.session_state.filter_views["Vue par défaut"] = list(node_types)
|
| 208 |
st.session_state.current_view = "Vue par défaut"
|
|
@@ -235,7 +255,9 @@ def doc_dialog_main():
|
|
| 235 |
default_target_filter = filter_correspondance(st.session_state.filter_views[st.session_state.current_view],dict_filters)
|
| 236 |
# st.write(default_target_filter)
|
| 237 |
# st.write(dict_filters)
|
| 238 |
-
|
|
|
|
|
|
|
| 239 |
filter = filter_col.multiselect("Filtrer selon l'étiquette",target_filter,placeholder="Sélectionner une ou plusieurs étiquettes",default=default_target_filter,label_visibility="collapsed")
|
| 240 |
filter = filter_correspondance(filter,dict_filters,reverse=True)
|
| 241 |
if add_view_col.button("➕",help="Ajouter une vue"):
|
|
@@ -292,16 +314,11 @@ def doc_dialog_main():
|
|
| 292 |
# col_copy_c , col_success_c = st.columns([1,7])
|
| 293 |
# if col_copy_c.button("📋",key="copy_graph_chat"):
|
| 294 |
with st.container(height=50,border=False):
|
| 295 |
-
|
| 296 |
-
st_copy_to_clipboard(chat_formatted,key="cp_but_graph_chat")
|
| 297 |
# col_success_c.success("Historique copié !")
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
doc_dialog_main()
|
| 306 |
|
| 307 |
|
|
|
|
| 8 |
from audit_page.knowledge_graph import *
|
| 9 |
import json
|
| 10 |
import clipboard
|
| 11 |
+
from time import sleep
|
| 12 |
|
| 13 |
def graph_doc_to_json(graph):
|
| 14 |
nodes = []
|
|
|
|
| 31 |
formatted_chat = ""
|
| 32 |
for message in chat_history:
|
| 33 |
if isinstance(message, AIMessage):
|
| 34 |
+
formatted_chat += f"AI:{message.content}\n\n"
|
| 35 |
elif isinstance(message, HumanMessage):
|
| 36 |
+
formatted_chat += f"Human:{message.content}\n\n"
|
| 37 |
return formatted_chat
|
| 38 |
|
| 39 |
def filter_correspondance(source_list:list[str],ref_dict:dict,reverse=False):
|
|
|
|
| 44 |
# st.write(source_list)
|
| 45 |
# st.write(ref_dict.keys())
|
| 46 |
return [value for key, value in ref_dict.items() if key.lower().strip() in source_list]
|
| 47 |
+
|
| 48 |
+
@st.fragment()
|
| 49 |
+
def radio_choice():
|
| 50 |
+
options = ["compte_rendu","graphe de connaissance"]
|
| 51 |
+
choice = st.radio("Choisissez une option",options,index=st.session_state.radio_choice,horizontal=True,label_visibility="collapsed")
|
| 52 |
+
sleep(1)
|
| 53 |
+
if choice and options.index(choice) != st.session_state.radio_choice:
|
| 54 |
+
sleep(1)
|
| 55 |
+
st.session_state.radio_choice = options.index(choice)
|
| 56 |
+
return choice
|
| 57 |
|
| 58 |
|
| 59 |
def doc_dialog_main():
|
|
|
|
| 85 |
if "chat_graph_history" not in st.session_state:
|
| 86 |
st.session_state.chat_graph_history = []
|
| 87 |
|
| 88 |
+
#init a radio button for the choice
|
| 89 |
if "radio_choice" not in st.session_state:
|
| 90 |
st.session_state.radio_choice = None
|
| 91 |
+
# if "choice" not in st.session_state:
|
| 92 |
+
# st.session_state.choice = st.radio("Choisissez une option",["compte_rendu","graphe de connaissance"],index=st.session_state.radio_choice,horizontal=True,label_visibility="collapsed")
|
| 93 |
|
| 94 |
+
# choice = radio_choice()
|
| 95 |
+
|
| 96 |
options = ["compte_rendu","graphe de connaissance"]
|
| 97 |
choice = st.radio("Choisissez une option",options,index=st.session_state.radio_choice,horizontal=True,label_visibility="collapsed")
|
| 98 |
+
if choice and options.index(choice) != st.session_state.radio_choice:
|
| 99 |
st.session_state.radio_choice = options.index(choice)
|
| 100 |
+
|
| 101 |
|
| 102 |
audit = st.session_state.audit_simplified
|
| 103 |
content = st.session_state.audit["content"]
|
|
|
|
| 203 |
# if col_copy_c.button("📋",key="copy_cr_chat"):
|
| 204 |
with st.container(height=50,border=False):
|
| 205 |
chat_formatted = chat_history_formatter(st.session_state.cr_chat_history)
|
| 206 |
+
st_copy_to_clipboard(chat_formatted,key="cp_but_cr_chat",show_text=False)
|
| 207 |
# col_success_c.success("Historique copié !")
|
| 208 |
|
| 209 |
elif choice == "graphe de connaissance":
|
|
|
|
| 219 |
st.session_state.chat_graph_history = []
|
| 220 |
|
| 221 |
node_types = get_node_types(graph[0])
|
| 222 |
+
list_node_types = list(node_types)
|
| 223 |
+
sorted_node_types = sorted(list_node_types,key=lambda x: x.lower())
|
| 224 |
+
print(sorted_node_types)
|
| 225 |
+
nodes_type_dict = list_to_dict_colors(sorted_node_types)
|
| 226 |
st.session_state.node_types = nodes_type_dict
|
| 227 |
st.session_state.filter_views["Vue par défaut"] = list(node_types)
|
| 228 |
st.session_state.current_view = "Vue par défaut"
|
|
|
|
| 255 |
default_target_filter = filter_correspondance(st.session_state.filter_views[st.session_state.current_view],dict_filters)
|
| 256 |
# st.write(default_target_filter)
|
| 257 |
# st.write(dict_filters)
|
| 258 |
+
sorted_default_target_filter = sorted(default_target_filter,key=lambda x: x.lower())
|
| 259 |
+
target_filter = filter_correspondance(list(st.session_state.node_types.keys()),dict_filters)
|
| 260 |
+
target_filter = sorted(target_filter,key=lambda x: x.lower())
|
| 261 |
filter = filter_col.multiselect("Filtrer selon l'étiquette",target_filter,placeholder="Sélectionner une ou plusieurs étiquettes",default=default_target_filter,label_visibility="collapsed")
|
| 262 |
filter = filter_correspondance(filter,dict_filters,reverse=True)
|
| 263 |
if add_view_col.button("➕",help="Ajouter une vue"):
|
|
|
|
| 314 |
# col_copy_c , col_success_c = st.columns([1,7])
|
| 315 |
# if col_copy_c.button("📋",key="copy_graph_chat"):
|
| 316 |
with st.container(height=50,border=False):
|
| 317 |
+
st_copy_to_clipboard(chat_history_formatter(st.session_state.chat_graph_history),key="cp_but_graph_chat",show_text=False)
|
|
|
|
| 318 |
# col_success_c.success("Historique copié !")
|
| 319 |
|
| 320 |
|
| 321 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 322 |
doc_dialog_main()
|
| 323 |
|
| 324 |
|
audit_page/knowledge_graph.py
CHANGED
|
@@ -159,6 +159,13 @@ def change_view_dialog():
|
|
| 159 |
st.rerun()
|
| 160 |
if len(st.session_state.filter_views.keys()) > index:
|
| 161 |
with col1.expander(item):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
st.markdown("\n".join(f"- {label.strip()}" for label in st.session_state.filter_views[item]))
|
| 163 |
else:
|
| 164 |
emp.empty()
|
|
|
|
| 159 |
st.rerun()
|
| 160 |
if len(st.session_state.filter_views.keys()) > index:
|
| 161 |
with col1.expander(item):
|
| 162 |
+
if index > 0:
|
| 163 |
+
change_name = st.text_input("Nom de la vue", label_visibility="collapsed", placeholder="Changez le nom de la vue",key=f"change_name{index}")
|
| 164 |
+
if st.button("Renommer",key=f"rename{index}"):
|
| 165 |
+
if change_name != "":
|
| 166 |
+
st.session_state.filter_views[change_name] = st.session_state.filter_views.pop(item)
|
| 167 |
+
st.session_state.current_view = change_name
|
| 168 |
+
st.rerun()
|
| 169 |
st.markdown("\n".join(f"- {label.strip()}" for label in st.session_state.filter_views[item]))
|
| 170 |
else:
|
| 171 |
emp.empty()
|