Spaces:
Sleeping
Sleeping
Download component/graph_view.py from mgbam/MCP_Research: direct link, hf CLI and curl.
- Browser
- Download file 792 Bytes
-
https://huggingface.co/spaces/mgbam/MCP_Research/resolve/75e32f7da4167bce4cb03e860da9f44c4f9a0b3a/component/graph_view.py
- Command line
-
hf download hf://spaces/mgbam/MCP_Research@75e32f7da4167bce4cb03e860da9f44c4f9a0b3a/component/graph_view.py
-
curl -L -o graph_view.py https://huggingface.co/spaces/mgbam/MCP_Research/resolve/75e32f7da4167bce4cb03e860da9f44c4f9a0b3a/component/graph_view.py
792 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 += "}" | |
| st.graphviz_chart(dot) |