MCP_Research / components /graph_view.py
mgbam's picture
Create graph_view.py
b50df8d verified
raw
history blame
765 Bytes
# Graph view component
# File: components/graph_view.py
import streamlit as st
def render_graph(graph_data):
"""
Display a knowledge graph using Streamlit's Graphviz support.
Args:
graph_data (dict): {
'nodes': [{'id': str, 'label': str}],
'edges': [{'source': str, 'target': str}]
}
"""
st.header("πŸ”— Knowledge Graph")
if not graph_data or not graph_data.get('nodes'):
st.info("No graph data to display.")
return
# Build DOT string
dot = "digraph G {\n"
for node in graph_data['nodes']:
dot += f" {node['id']} [label=\"{node['label']}\"];\n"
for edge in graph_data['edges']:
dot += f" {edge['source']} -> {edge['target']};\n"
dot += "}"