Spaces:
Runtime error
Runtime error
Update graph_view.py
Browse files- graph_view.py +14 -14
graph_view.py
CHANGED
|
@@ -1,21 +1,21 @@
|
|
| 1 |
-
|
| 2 |
-
import matplotlib.pyplot as plt
|
| 3 |
-
|
| 4 |
-
def visualize_graph(memories):
|
| 5 |
-
G = nx.Graph()
|
| 6 |
-
for m in memories:
|
| 7 |
-
for other in memories:
|
| 8 |
-
if m != other:
|
| 9 |
-
G.add_edge(m['text'][:20], other['text'][:20])
|
| 10 |
-
plt.figure(figsize=(8,6))
|
| 11 |
-
nx.draw(G, with_labels=True, node_color='lightblue', font_size=8)
|
| 12 |
-
plt.show()
|
| 13 |
-
def visualize_reasoned_graph(memories, relationships, output_html="/mnt/data/graph_reasoned.html"):
|
| 14 |
from pyvis.network import Network
|
|
|
|
|
|
|
| 15 |
net = Network(height="600px", width="100%", bgcolor="#000000", font_color="white")
|
|
|
|
|
|
|
| 16 |
for m in memories:
|
| 17 |
net.add_node(m["text"], label=m["text"], color="#00aaff")
|
|
|
|
|
|
|
| 18 |
for r in relationships:
|
| 19 |
-
net.add_edge(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
net.show(output_html)
|
| 21 |
return output_html
|
|
|
|
| 1 |
+
def visualize_reasoned_graph(memories, relationships, output_html="/mnt/data/graph_reasoned.html"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
from pyvis.network import Network
|
| 3 |
+
|
| 4 |
+
# Initialize graph
|
| 5 |
net = Network(height="600px", width="100%", bgcolor="#000000", font_color="white")
|
| 6 |
+
|
| 7 |
+
# Add nodes (each memory)
|
| 8 |
for m in memories:
|
| 9 |
net.add_node(m["text"], label=m["text"], color="#00aaff")
|
| 10 |
+
|
| 11 |
+
# Add edges (relationships between memories)
|
| 12 |
for r in relationships:
|
| 13 |
+
net.add_edge(
|
| 14 |
+
r["source"], r["target"],
|
| 15 |
+
value=r["weight"],
|
| 16 |
+
title=f"Similarity: {r['weight']}"
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
# Export visualization
|
| 20 |
net.show(output_html)
|
| 21 |
return output_html
|