shukdevdatta123 commited on
Commit
2f89284
·
verified ·
1 Parent(s): 0bcf063

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -38
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 random graph
49
- G = nx.gnm_random_graph(n, m, seed=seed)
50
-
51
- # Display node properties
52
- st.write("### Node Degree and Clustering Coefficient")
53
- for v in nx.nodes(G):
54
- st.write(f"Node {v}: Degree = {nx.degree(G, v)}, Clustering Coefficient = {nx.clustering(G, v)}")
55
-
56
- # Display adjacency list
57
- st.write("### Adjacency List")
58
- adj_list = "\n".join([line for line in nx.generate_adjlist(G)])
59
- st.text(adj_list)
60
-
61
- # Visualize the graph
62
- pos = nx.spring_layout(G, seed=seed) # Seed for reproducible layout
63
- fig, ax = plt.subplots()
64
- nx.draw(G, pos=pos, ax=ax, with_labels=True, node_color="skyblue", edge_color="gray")
65
- ax.set_title("Erdos-Renyi Random Graph")
66
- st.pyplot(fig)
 
 
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 random graph
78
- G = nx.gnm_random_graph(n, m, seed=seed)
79
-
80
- # Display node properties
81
- st.write("### Node Degree and Clustering Coefficient")
82
- for v in nx.nodes(G):
83
- st.write(f"Node {v}: Degree = {nx.degree(G, v)}, Clustering Coefficient = {nx.clustering(G, v)}")
84
-
85
- # Display adjacency list
86
- st.write("### Adjacency List")
87
- adj_list = "\n".join([line for line in nx.generate_adjlist(G)])
88
- st.text(adj_list)
89
-
90
- # Visualize the graph
91
- pos = nx.spring_layout(G, seed=seed) # Seed for reproducible layout
92
- fig, ax = plt.subplots()
93
- nx.draw(G, pos=pos, ax=ax, with_labels=True, node_color="skyblue", edge_color="gray")
94
- ax.set_title("Erdos-Renyi Random Graph")
95
- st.pyplot(fig)
 
 
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":