shukdevdatta123 commited on
Commit
67fc410
·
verified ·
1 Parent(s): f4f6fdb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -12
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
- # Create random graph with user input
66
- G = nx.gnm_random_graph(num_nodes, num_edges)
 
 
67
 
68
- # Display node degree
69
- st.write("### Node Degree")
70
- for v in G:
71
- st.write(f"Node {v:4}: Degree = {G.degree(v)}")
72
 
73
- # Visualize the graph using circular layout
74
- st.write("### Graph Visualization")
75
- fig, ax = plt.subplots()
76
- nx.draw_circular(G, with_labels=True, ax=ax, node_color="lightgreen", edge_color="gray")
77
- ax.set_title("Custom Graph")
78
- st.pyplot(fig)
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":