LightRAG/examples/graph_visual_with_html.py

20 lines
470 B
Python
Raw Normal View History

2024-10-20 09:55:52 +08:00
import networkx as nx
from pyvis.network import Network
import random
2024-10-20 09:55:52 +08:00
# Load the GraphML file
2024-10-25 13:32:25 +05:30
G = nx.read_graphml("./dickens/graph_chunk_entity_relation.graphml")
2024-10-20 09:55:52 +08:00
# Create a Pyvis network
2024-10-26 14:04:11 +08:00
net = Network(height="100vh", notebook=True)
2024-10-20 09:55:52 +08:00
# Convert NetworkX graph to Pyvis network
net.from_nx(G)
# Add colors to nodes
for node in net.nodes:
2024-10-25 13:32:25 +05:30
node["color"] = "#{:06x}".format(random.randint(0, 0xFFFFFF))
2024-10-20 09:55:52 +08:00
# Save and display the network
2024-10-25 13:32:25 +05:30
net.show("knowledge_graph.html")