Spaces:
Sleeping
Sleeping
# 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 += "}" | |