Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from pyvis.network import Network
|
3 |
+
import networkx as nx
|
4 |
+
import tempfile
|
5 |
+
|
6 |
+
# Create a graph
|
7 |
+
G = nx.fast_gnp_random_graph(n=10, p=0.2)
|
8 |
+
|
9 |
+
# Convert NetworkX graph to PyVis graph
|
10 |
+
nt = Network("500px", "500px", notebook=True)
|
11 |
+
nt.from_nx(G)
|
12 |
+
|
13 |
+
# Generate the graph to an HTML file
|
14 |
+
tmp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.html')
|
15 |
+
nt.save_graph(tmp_file.name)
|
16 |
+
|
17 |
+
# Use Streamlit components to display the graph
|
18 |
+
st.components.v1.html(tmp_file.read(), height=500, scrolling=False)
|