Last commit not found
# test_build_and_visualize_graph.py | |
import os | |
import sys | |
import json | |
import networkx as nx | |
# Add the path to access agn_service | |
sys.path.append(os.path.join(os.path.dirname(__file__), "../")) | |
from app.services.agn_service.load_graph import load_graph | |
from app.services.agn_service.build_graph_from_index import build_graph_from_index | |
from app.services.agn_service.visualize_graph import visualize_graph | |
# Define paths | |
index_file_path = "graphs/index.json" # Path to index.json file | |
output_image = "test_graph_visualization.png" | |
# Load index data | |
def load_index_data(file_path): | |
with open(file_path, "r") as file: | |
return json.load(file) | |
# Main execution | |
if __name__ == "__main__": | |
# Step 1: Load index data from index.json | |
data = load_index_data(index_file_path) | |
# Step 2: Build the graph using the data loaded from index.json | |
G = build_graph_from_index(data) | |
# Step 3: Generate and save the graph visualization | |
if G: | |
visualize_graph(G, output_file=output_image) | |
print(f"Graph visualization generated and saved as {output_image}") | |
else: | |
print("Failed to build graph.") |