Format entire codebase with ruff and add type hints across all modules: - Apply ruff formatting to all Python files (121 files, 17K insertions) - Add type hints to function signatures throughout lightrag core and API - Update test suite with improved type annotations and docstrings - Add pyrightconfig.json for static type checking configuration - Create prompt_optimized.py and test_extraction_prompt_ab.py test files - Update ruff.toml and .gitignore for improved linting configuration - Standardize code style across examples, reproduce scripts, and utilities
35 lines
812 B
Python
35 lines
812 B
Python
import pipmaster as pm
|
|
|
|
if not pm.is_installed('pyvis'):
|
|
pm.install('pyvis')
|
|
if not pm.is_installed('networkx'):
|
|
pm.install('networkx')
|
|
|
|
import random
|
|
|
|
import networkx as nx
|
|
from pyvis.network import Network
|
|
|
|
# Load the GraphML file
|
|
G = nx.read_graphml('./dickens/graph_chunk_entity_relation.graphml')
|
|
|
|
# Create a Pyvis network
|
|
net = Network(height='100vh', notebook=True)
|
|
|
|
# Convert NetworkX graph to Pyvis network
|
|
net.from_nx(G)
|
|
|
|
|
|
# Add colors and title to nodes
|
|
for node in net.nodes:
|
|
node['color'] = f'#{random.randint(0, 0xFFFFFF):06x}'
|
|
if 'description' in node:
|
|
node['title'] = node['description']
|
|
|
|
# Add title to edges
|
|
for edge in net.edges:
|
|
if 'description' in edge:
|
|
edge['title'] = edge['description']
|
|
|
|
# Save and display the network
|
|
net.show('knowledge_graph.html')
|