File size: 1,213 Bytes
941f05b
7e4391d
9245419
941f05b
7e4391d
f105d7d
 
7e4391d
941f05b
 
9245419
941f05b
 
9245419
941f05b
 
 
 
 
 
 
9245419
941f05b
 
 
 
f105d7d
 
 
 
0b9b5e7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os
from pyvis.network import Network

def visualize_reasoned_graph(memories, relationships):
    """
    Generates an interactive graph of your memory network.
    Safe for headless environments like Hugging Face Spaces.
    """
    net = Network(height="700px", width="100%", bgcolor="#0d0d0d", font_color="white", notebook=False)
    net.barnes_hut(gravity=-30000, central_gravity=0.3, spring_length=150, spring_strength=0.05)

    for i, memory in enumerate(memories):
        net.add_node(i, label=memory, title=memory, color="#4fc3f7")

    for rel in relationships:
        src, tgt, sim = rel
        src_idx = memories.index(src)
        tgt_idx = memories.index(tgt)
        width = max(1, sim * 10)
        color = "#00e676" if sim > 0.5 else "#ffeb3b" if sim > 0.3 else "#ff1744"
        net.add_edge(src_idx, tgt_idx, value=sim, color=color, width=width, title=f"Similarity: {sim:.2f}")

    output_dir = "/mnt/data"
    os.makedirs(output_dir, exist_ok=True)
    output_html = os.path.join(output_dir, "graph_reasoned.html")

    # ✅ write_html instead of show()
    net.write_html(output_html)

    print(f"✅ Visualization generated successfully at: {output_html}")
    return output_html