Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -61,21 +61,24 @@ def karate_club_graph():
|
|
61 |
# Allow user to input the number of nodes and edges for custom graph
|
62 |
num_nodes = st.number_input("Number of nodes", min_value=2, value=10)
|
63 |
num_edges = st.number_input("Number of edges", min_value=1, value=15)
|
|
|
64 |
|
65 |
-
#
|
66 |
-
|
|
|
|
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
|
80 |
# Display the corresponding page based on sidebar option
|
81 |
if sidebar_option == "Graph: Karate Club":
|
|
|
61 |
# Allow user to input the number of nodes and edges for custom graph
|
62 |
num_nodes = st.number_input("Number of nodes", min_value=2, value=10)
|
63 |
num_edges = st.number_input("Number of edges", min_value=1, value=15)
|
64 |
+
seed = st.number_input("Seed for Random Graph (optional)", value=20160)
|
65 |
|
66 |
+
# Generate graph button
|
67 |
+
if st.button("Generate Graph"):
|
68 |
+
# Create random graph with user input
|
69 |
+
G = nx.gnm_random_graph(num_nodes, num_edges, seed=seed)
|
70 |
|
71 |
+
# Display node degree
|
72 |
+
st.write("### Node Degree")
|
73 |
+
for v in G:
|
74 |
+
st.write(f"Node {v:4}: Degree = {G.degree(v)}")
|
75 |
|
76 |
+
# Visualize the graph using circular layout
|
77 |
+
st.write("### Graph Visualization")
|
78 |
+
fig, ax = plt.subplots()
|
79 |
+
nx.draw_circular(G, with_labels=True, ax=ax, node_color="lightgreen", edge_color="gray")
|
80 |
+
ax.set_title("Custom Graph")
|
81 |
+
st.pyplot(fig)
|
82 |
|
83 |
# Display the corresponding page based on sidebar option
|
84 |
if sidebar_option == "Graph: Karate Club":
|