Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -45,25 +45,27 @@ def erdos_renyi_graph():
|
|
45 |
m = 20 # 20 edges
|
46 |
seed = 20160 # seed random number generators for reproducibility
|
47 |
|
48 |
-
# Create
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
st.write(
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
|
|
|
|
67 |
|
68 |
elif graph_mode == "Create Your Own":
|
69 |
st.write("### Create Your Own Random Erdos-Renyi Graph")
|
@@ -74,25 +76,27 @@ def erdos_renyi_graph():
|
|
74 |
|
75 |
seed = st.number_input("Seed", value=20160)
|
76 |
|
77 |
-
# Create
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
st.write(
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
|
|
|
|
96 |
|
97 |
# Display the corresponding page based on sidebar option
|
98 |
if sidebar_option == "Graph: Erdos Renyi":
|
|
|
45 |
m = 20 # 20 edges
|
46 |
seed = 20160 # seed random number generators for reproducibility
|
47 |
|
48 |
+
# Create a button for generating the graph
|
49 |
+
if st.button("Generate Graph"):
|
50 |
+
# Create random graph
|
51 |
+
G = nx.gnm_random_graph(n, m, seed=seed)
|
52 |
+
|
53 |
+
# Display node properties
|
54 |
+
st.write("### Node Degree and Clustering Coefficient")
|
55 |
+
for v in nx.nodes(G):
|
56 |
+
st.write(f"Node {v}: Degree = {nx.degree(G, v)}, Clustering Coefficient = {nx.clustering(G, v)}")
|
57 |
+
|
58 |
+
# Display adjacency list
|
59 |
+
st.write("### Adjacency List")
|
60 |
+
adj_list = "\n".join([line for line in nx.generate_adjlist(G)])
|
61 |
+
st.text(adj_list)
|
62 |
+
|
63 |
+
# Visualize the graph
|
64 |
+
pos = nx.spring_layout(G, seed=seed) # Seed for reproducible layout
|
65 |
+
fig, ax = plt.subplots()
|
66 |
+
nx.draw(G, pos=pos, ax=ax, with_labels=True, node_color="skyblue", edge_color="gray")
|
67 |
+
ax.set_title("Erdos-Renyi Random Graph")
|
68 |
+
st.pyplot(fig)
|
69 |
|
70 |
elif graph_mode == "Create Your Own":
|
71 |
st.write("### Create Your Own Random Erdos-Renyi Graph")
|
|
|
76 |
|
77 |
seed = st.number_input("Seed", value=20160)
|
78 |
|
79 |
+
# Create a button for generating the graph
|
80 |
+
if st.button("Generate Graph"):
|
81 |
+
# Create random graph
|
82 |
+
G = nx.gnm_random_graph(n, m, seed=seed)
|
83 |
+
|
84 |
+
# Display node properties
|
85 |
+
st.write("### Node Degree and Clustering Coefficient")
|
86 |
+
for v in nx.nodes(G):
|
87 |
+
st.write(f"Node {v}: Degree = {nx.degree(G, v)}, Clustering Coefficient = {nx.clustering(G, v)}")
|
88 |
+
|
89 |
+
# Display adjacency list
|
90 |
+
st.write("### Adjacency List")
|
91 |
+
adj_list = "\n".join([line for line in nx.generate_adjlist(G)])
|
92 |
+
st.text(adj_list)
|
93 |
+
|
94 |
+
# Visualize the graph
|
95 |
+
pos = nx.spring_layout(G, seed=seed) # Seed for reproducible layout
|
96 |
+
fig, ax = plt.subplots()
|
97 |
+
nx.draw(G, pos=pos, ax=ax, with_labels=True, node_color="skyblue", edge_color="gray")
|
98 |
+
ax.set_title("Erdos-Renyi Random Graph")
|
99 |
+
st.pyplot(fig)
|
100 |
|
101 |
# Display the corresponding page based on sidebar option
|
102 |
if sidebar_option == "Graph: Erdos Renyi":
|