Spaces:
Runtime error
Runtime error
Update graph_view.py
Browse files- graph_view.py +6 -7
graph_view.py
CHANGED
|
@@ -3,17 +3,15 @@ from pyvis.network import Network
|
|
| 3 |
|
| 4 |
def visualize_reasoned_graph(memories, relationships):
|
| 5 |
"""
|
| 6 |
-
|
| 7 |
-
|
| 8 |
"""
|
| 9 |
net = Network(height="700px", width="100%", bgcolor="#0d0d0d", font_color="white", notebook=False)
|
| 10 |
net.barnes_hut(gravity=-30000, central_gravity=0.3, spring_length=150, spring_strength=0.05)
|
| 11 |
|
| 12 |
-
# Add memory nodes
|
| 13 |
for i, memory in enumerate(memories):
|
| 14 |
net.add_node(i, label=memory, title=memory, color="#4fc3f7")
|
| 15 |
|
| 16 |
-
# Add relationships
|
| 17 |
for rel in relationships:
|
| 18 |
src, tgt, sim = rel
|
| 19 |
src_idx = memories.index(src)
|
|
@@ -22,11 +20,12 @@ def visualize_reasoned_graph(memories, relationships):
|
|
| 22 |
color = "#00e676" if sim > 0.5 else "#ffeb3b" if sim > 0.3 else "#ff1744"
|
| 23 |
net.add_edge(src_idx, tgt_idx, value=sim, color=color, width=width, title=f"Similarity: {sim:.2f}")
|
| 24 |
|
| 25 |
-
# ✅ Ensure directory exists before writing HTML
|
| 26 |
output_dir = "/mnt/data"
|
| 27 |
os.makedirs(output_dir, exist_ok=True)
|
| 28 |
output_html = os.path.join(output_dir, "graph_reasoned.html")
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
return output_html
|
|
|
|
| 3 |
|
| 4 |
def visualize_reasoned_graph(memories, relationships):
|
| 5 |
"""
|
| 6 |
+
Generates an interactive graph of your memory network.
|
| 7 |
+
Safe for headless environments like Hugging Face Spaces.
|
| 8 |
"""
|
| 9 |
net = Network(height="700px", width="100%", bgcolor="#0d0d0d", font_color="white", notebook=False)
|
| 10 |
net.barnes_hut(gravity=-30000, central_gravity=0.3, spring_length=150, spring_strength=0.05)
|
| 11 |
|
|
|
|
| 12 |
for i, memory in enumerate(memories):
|
| 13 |
net.add_node(i, label=memory, title=memory, color="#4fc3f7")
|
| 14 |
|
|
|
|
| 15 |
for rel in relationships:
|
| 16 |
src, tgt, sim = rel
|
| 17 |
src_idx = memories.index(src)
|
|
|
|
| 20 |
color = "#00e676" if sim > 0.5 else "#ffeb3b" if sim > 0.3 else "#ff1744"
|
| 21 |
net.add_edge(src_idx, tgt_idx, value=sim, color=color, width=width, title=f"Similarity: {sim:.2f}")
|
| 22 |
|
|
|
|
| 23 |
output_dir = "/mnt/data"
|
| 24 |
os.makedirs(output_dir, exist_ok=True)
|
| 25 |
output_html = os.path.join(output_dir, "graph_reasoned.html")
|
| 26 |
|
| 27 |
+
# ✅ write_html instead of show()
|
| 28 |
+
net.write_html(output_html)
|
| 29 |
+
|
| 30 |
+
print(f"✅ Visualization generated successfully at: {output_html}")
|
| 31 |
return output_html
|