Spaces:
Sleeping
Sleeping
File size: 765 Bytes
b50df8d |
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 |
# 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 += "}"
|