Spaces:
Sleeping
Sleeping
eaglelandsonce
commited on
Commit
•
b1de838
1
Parent(s):
245430a
Update pages/17_Graphs2.py
Browse files- 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 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|