Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import streamlit as st
|
|
| 2 |
import networkx as nx
|
| 3 |
from pyvis.network import Network
|
| 4 |
import json
|
| 5 |
-
import
|
| 6 |
|
| 7 |
# Streamlit app layout
|
| 8 |
st.title("Interactive Graph Visualization")
|
|
@@ -20,9 +20,6 @@ if uploaded_file is not None:
|
|
| 20 |
if "nodes" not in graph_data or "edges" not in graph_data:
|
| 21 |
raise ValueError("The JSON file must contain 'nodes' and 'edges' keys.")
|
| 22 |
|
| 23 |
-
if not isinstance(graph_data["nodes"], list) or not isinstance(graph_data["edges"], list):
|
| 24 |
-
raise ValueError("'nodes' and 'edges' must be lists.")
|
| 25 |
-
|
| 26 |
# Function to create a NetworkX graph from data
|
| 27 |
def create_graph(data):
|
| 28 |
G = nx.DiGraph()
|
|
@@ -53,17 +50,12 @@ if uploaded_file is not None:
|
|
| 53 |
# Create the Pyvis graph
|
| 54 |
pyvis_graph = create_pyvis_graph(graph)
|
| 55 |
|
| 56 |
-
#
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
# Display the graph in Streamlit
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
# Clean up the temporary file
|
| 65 |
-
if os.path.exists(output_file):
|
| 66 |
-
os.remove(output_file)
|
| 67 |
except Exception as e:
|
| 68 |
st.error(f"Error processing the file: {e}")
|
| 69 |
else:
|
|
|
|
| 2 |
import networkx as nx
|
| 3 |
from pyvis.network import Network
|
| 4 |
import json
|
| 5 |
+
from streamlit.components.v1 import html
|
| 6 |
|
| 7 |
# Streamlit app layout
|
| 8 |
st.title("Interactive Graph Visualization")
|
|
|
|
| 20 |
if "nodes" not in graph_data or "edges" not in graph_data:
|
| 21 |
raise ValueError("The JSON file must contain 'nodes' and 'edges' keys.")
|
| 22 |
|
|
|
|
|
|
|
|
|
|
| 23 |
# Function to create a NetworkX graph from data
|
| 24 |
def create_graph(data):
|
| 25 |
G = nx.DiGraph()
|
|
|
|
| 50 |
# Create the Pyvis graph
|
| 51 |
pyvis_graph = create_pyvis_graph(graph)
|
| 52 |
|
| 53 |
+
# Generate the HTML representation of the graph
|
| 54 |
+
pyvis_graph_html = pyvis_graph.generate_html()
|
| 55 |
+
|
|
|
|
| 56 |
# Display the graph in Streamlit
|
| 57 |
+
html(pyvis_graph_html, height=600)
|
| 58 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
except Exception as e:
|
| 60 |
st.error(f"Error processing the file: {e}")
|
| 61 |
else:
|