eaglelandsonce commited on
Commit
b1de838
1 Parent(s): 245430a

Update pages/17_Graphs2.py

Browse files
Files changed (1) hide show
  1. pages/17_Graphs2.py +39 -33
pages/17_Graphs2.py CHANGED
@@ -78,39 +78,45 @@ def create_sample_graph():
78
  def main():
79
  st.title("Graph Neural Network Architecture Visualization")
80
 
81
- # Create sample graph
82
- nx_graph, graph_tensor, node_features, edge_features = create_sample_graph()
83
-
84
- # Create and compile the model
85
- model = model_fn(graph_tensor.spec)
86
- model.compile(optimizer='adam', loss='binary_crossentropy')
87
-
88
- # Display model summary
89
- st.subheader("Model Summary")
90
- model.summary(print_fn=lambda x: st.text(x))
91
-
92
- # Visualize the graph
93
- st.subheader("Sample Graph Visualization")
94
- fig, ax = plt.subplots(figsize=(10, 8))
95
- pos = nx.spring_layout(nx_graph)
96
- labels = nx.get_node_attributes(nx_graph, 'title')
97
- nx.draw(nx_graph, pos, labels=labels, with_labels=True, node_color='lightblue',
98
- node_size=3000, arrowsize=20, ax=ax) # Increased node_size to 3000
99
- st.pyplot(fig)
100
-
101
- # Display graph tensor info
102
- st.subheader("Graph Tensor Information")
103
- st.text(f"Number of nodes: {graph_tensor.node_sets['papers'].total_size}")
104
- st.text(f"Number of edges: {graph_tensor.edge_sets['cites'].total_size}")
105
- st.text(f"Node feature shape: {graph_tensor.node_sets['papers']['features'].shape}")
106
- st.text(f"Edge feature shape: {graph_tensor.edge_sets['cites']['features'].shape}")
107
-
108
- # Display sample node and edge features
109
- st.subheader("Sample Node and Edge Features")
110
- st.write("Node Features (Year Published, Number of Authors):")
111
- st.write(node_features)
112
- st.write("Edge Features (Citation Weight):")
113
- st.write(edge_features)
 
 
 
 
 
 
114
 
115
  if __name__ == "__main__":
116
  main()
 
78
  def main():
79
  st.title("Graph Neural Network Architecture Visualization")
80
 
81
+ if st.button("Recreate Graph"):
82
+ recreate_graph = True
83
+ else:
84
+ recreate_graph = False
85
+
86
+ if recreate_graph:
87
+ # Create sample graph
88
+ nx_graph, graph_tensor, node_features, edge_features = create_sample_graph()
89
+
90
+ # Create and compile the model
91
+ model = model_fn(graph_tensor.spec)
92
+ model.compile(optimizer='adam', loss='binary_crossentropy')
93
+
94
+ # Display model summary
95
+ st.subheader("Model Summary")
96
+ model.summary(print_fn=lambda x: st.text(x))
97
+
98
+ # Visualize the graph
99
+ st.subheader("Sample Graph Visualization")
100
+ fig, ax = plt.subplots(figsize=(10, 8))
101
+ pos = nx.spring_layout(nx_graph)
102
+ labels = nx.get_node_attributes(nx_graph, 'title')
103
+ nx.draw(nx_graph, pos, labels=labels, with_labels=True, node_color='lightblue',
104
+ node_size=3000, arrowsize=20, ax=ax) # Increased node_size to 3000
105
+ st.pyplot(fig)
106
+
107
+ # Display graph tensor info
108
+ st.subheader("Graph Tensor Information")
109
+ st.text(f"Number of nodes: {graph_tensor.node_sets['papers'].total_size}")
110
+ st.text(f"Number of edges: {graph_tensor.edge_sets['cites'].total_size}")
111
+ st.text(f"Node feature shape: {graph_tensor.node_sets['papers']['features'].shape}")
112
+ st.text(f"Edge feature shape: {graph_tensor.edge_sets['cites']['features'].shape}")
113
+
114
+ # Display sample node and edge features
115
+ st.subheader("Sample Node and Edge Features")
116
+ st.write("Node Features (Year Published, Number of Authors):")
117
+ st.write(node_features)
118
+ st.write("Edge Features (Citation Weight):")
119
+ st.write(edge_features)
120
 
121
  if __name__ == "__main__":
122
  main()