Spaces:
Running
Running
Ilyas KHIAT
commited on
Commit
·
07a1739
1
Parent(s):
d07e69f
analyse
Browse files
audit_page/knowledge_graph.py
CHANGED
@@ -275,13 +275,36 @@ def format_relationships(relationships : list[Edge]):
|
|
275 |
for rel in relationships
|
276 |
)
|
277 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
278 |
def add_relationship_to_graph(source_id, target_id, relationship_type):
|
279 |
st.session_state.edges.append(Edge(source=source_id, label=relationship_type, target=target_id))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
280 |
|
281 |
def delete_relationship_from_graph(source_id, target_id, relationship_type):
|
282 |
st.session_state.edges = [edge for edge in st.session_state.edges if not (
|
283 |
edge.source == source_id and edge.to == target_id and edge.label == relationship_type
|
284 |
)]
|
|
|
|
|
285 |
|
286 |
|
287 |
|
@@ -360,6 +383,8 @@ def change_color_dialog():
|
|
360 |
f"La couleur de l'entité **{node_type.strip()}**",
|
361 |
color
|
362 |
)
|
|
|
|
|
363 |
st.session_state.node_types[node_type] = new_color
|
364 |
|
365 |
if st.button("Valider"):
|
@@ -408,6 +433,8 @@ def kg_main():
|
|
408 |
|
409 |
print("Graph loaded.")
|
410 |
|
|
|
|
|
411 |
# 2. Initialize other session keys if they don’t exist
|
412 |
if "filter_views" not in st.session_state:
|
413 |
st.session_state.filter_views = {}
|
@@ -446,6 +473,15 @@ def kg_main():
|
|
446 |
config = st.session_state.config
|
447 |
print("Graph converti en Agraph")
|
448 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
449 |
# 4. UI layout: (left) the graph itself, (right) the chat
|
450 |
col1, col2 = st.columns([3, 1])
|
451 |
|
|
|
275 |
for rel in relationships
|
276 |
)
|
277 |
|
278 |
+
def fortmat_nodes(nodes : list[Node]):
|
279 |
+
"""Format nodes for display in the chat."""
|
280 |
+
return "\n".join(
|
281 |
+
f"- **{node.label}** ({node.title})"
|
282 |
+
for node in nodes
|
283 |
+
)
|
284 |
+
|
285 |
def add_relationship_to_graph(source_id, target_id, relationship_type):
|
286 |
st.session_state.edges.append(Edge(source=source_id, label=relationship_type, target=target_id))
|
287 |
+
print(f"Relation ajoutée: {source_id} -- {relationship_type} --> {target_id}")
|
288 |
+
|
289 |
+
if not if_node_exists(st.session_state.nodes, source_id):
|
290 |
+
st.session_state.nodes.append(Node(
|
291 |
+
id=source_id,
|
292 |
+
title="Autre",
|
293 |
+
label=source_id,
|
294 |
+
size=25,
|
295 |
+
shape="circle",
|
296 |
+
color=st.session_state.node_types.get(target.label, "#CCCCCC")
|
297 |
+
))
|
298 |
+
print(f"Node ajouté: {source_id}")
|
299 |
+
|
300 |
+
print(f"Nodes: {fortmat_nodes(st.session_state.nodes)}")
|
301 |
|
302 |
def delete_relationship_from_graph(source_id, target_id, relationship_type):
|
303 |
st.session_state.edges = [edge for edge in st.session_state.edges if not (
|
304 |
edge.source == source_id and edge.to == target_id and edge.label == relationship_type
|
305 |
)]
|
306 |
+
|
307 |
+
|
308 |
|
309 |
|
310 |
|
|
|
383 |
f"La couleur de l'entité **{node_type.strip()}**",
|
384 |
color
|
385 |
)
|
386 |
+
print("New color:", new_color)
|
387 |
+
print("Old color:", color)
|
388 |
st.session_state.node_types[node_type] = new_color
|
389 |
|
390 |
if st.button("Valider"):
|
|
|
433 |
|
434 |
print("Graph loaded.")
|
435 |
|
436 |
+
|
437 |
+
|
438 |
# 2. Initialize other session keys if they don’t exist
|
439 |
if "filter_views" not in st.session_state:
|
440 |
st.session_state.filter_views = {}
|
|
|
473 |
config = st.session_state.config
|
474 |
print("Graph converti en Agraph")
|
475 |
|
476 |
+
#ask chatgpt to analyse the graph
|
477 |
+
prompt = ("Tu es un expert en graphes de connaissances, analyse le graphe et donne une synthèse et differentes conclusions sur les elements du recit, tout en etant pertinent et precis",
|
478 |
+
"**Graphe**:,"
|
479 |
+
f"**Noeuds**: {fortmat_nodes(st.session_state.nodes)}\n"
|
480 |
+
f"Relations: {format_relationships(st.session_state.edges)}",
|
481 |
+
"Output: tu dois donner une synthèse et des conclusions sur les elements du recit , ca sera le premier message de la conversation"),
|
482 |
+
response = generate_response_via_langchain(prompt)
|
483 |
+
st.session_state.chat_graph_history.append(AIMessage(content=response))
|
484 |
+
|
485 |
# 4. UI layout: (left) the graph itself, (right) the chat
|
486 |
col1, col2 = st.columns([3, 1])
|
487 |
|