Spaces:
Sleeping
Sleeping
File size: 866 Bytes
e6583bf |
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 |
from IPython.display import Image, display
from pathlib import Path
def graph_visualiser(graph, filename: str = "graph.jpg", show: bool = True):
"""
Visualize and save the compiled LangGraph as a .jpg image.
Args:
graph: Compiled LangGraph object.
filename (str): Path to save the image.
show (bool): Whether to display the image in notebook (optional).
"""
try:
# Get raw image data
image_data = graph.get_graph().draw_mermaid_png()
# Save to file
output_path = Path(filename)
with open(output_path, "wb") as f:
f.write(image_data)
if show:
display(Image(filename))
print(f"β
Graph image saved as: {output_path.resolve()}")
except Exception as e:
print(f"β Failed to generate graph image: {e}") |