Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -62,7 +62,7 @@ def triads_graph():
|
|
62 |
}
|
63 |
|
64 |
fig, axes = plt.subplots(4, 4, figsize=(10, 10))
|
65 |
-
|
66 |
for (title, triad), ax in zip(triads.items(), axes.flatten()):
|
67 |
G = nx.DiGraph()
|
68 |
G.add_nodes_from([1, 2, 3])
|
@@ -70,7 +70,7 @@ def triads_graph():
|
|
70 |
nx.draw_networkx(
|
71 |
G,
|
72 |
ax=ax,
|
73 |
-
with_labels=
|
74 |
node_color=["green"],
|
75 |
node_size=200,
|
76 |
arrowsize=20,
|
@@ -99,47 +99,49 @@ def triads_graph():
|
|
99 |
"Enter your triads in the format: {'triad_name': [(edge1), (edge2), ...]}",
|
100 |
value="{'003': [], '012': [(1, 2)]}"
|
101 |
)
|
102 |
-
|
103 |
-
#
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
if
|
109 |
-
axes =
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
|
|
|
|
143 |
|
144 |
# Display the corresponding page based on sidebar option
|
145 |
if sidebar_option == "Graph: Triads":
|
|
|
62 |
}
|
63 |
|
64 |
fig, axes = plt.subplots(4, 4, figsize=(10, 10))
|
65 |
+
|
66 |
for (title, triad), ax in zip(triads.items(), axes.flatten()):
|
67 |
G = nx.DiGraph()
|
68 |
G.add_nodes_from([1, 2, 3])
|
|
|
70 |
nx.draw_networkx(
|
71 |
G,
|
72 |
ax=ax,
|
73 |
+
with_labels=True, # Labels the vertices
|
74 |
node_color=["green"],
|
75 |
node_size=200,
|
76 |
arrowsize=20,
|
|
|
99 |
"Enter your triads in the format: {'triad_name': [(edge1), (edge2), ...]}",
|
100 |
value="{'003': [], '012': [(1, 2)]}"
|
101 |
)
|
102 |
+
|
103 |
+
# Generate Button
|
104 |
+
if st.button("Generate Graph"):
|
105 |
+
# Try to evaluate the input as a dictionary of triads
|
106 |
+
try:
|
107 |
+
custom_triads = eval(triad_input)
|
108 |
+
if isinstance(custom_triads, dict) and all(isinstance(value, list) and all(isinstance(edge, tuple) and len(edge) == 2 for edge in value) for value in custom_triads.values()):
|
109 |
+
fig, axes = plt.subplots(len(custom_triads), 1, figsize=(10, len(custom_triads) * 5))
|
110 |
+
if len(custom_triads) == 1: # Handle case where only one triad is entered
|
111 |
+
axes = [axes]
|
112 |
+
|
113 |
+
for (title, triad), ax in zip(custom_triads.items(), axes):
|
114 |
+
G = nx.DiGraph()
|
115 |
+
G.add_nodes_from([1, 2, 3])
|
116 |
+
G.add_edges_from(triad)
|
117 |
+
|
118 |
+
nx.draw_networkx(
|
119 |
+
G,
|
120 |
+
ax=ax,
|
121 |
+
with_labels=True, # Labels the vertices
|
122 |
+
node_color=["green"],
|
123 |
+
node_size=200,
|
124 |
+
arrowsize=20,
|
125 |
+
width=2,
|
126 |
+
pos=nx.planar_layout(G),
|
127 |
+
)
|
128 |
+
ax.set_xlim(val * 1.2 for val in ax.get_xlim())
|
129 |
+
ax.set_ylim(val * 1.2 for val in ax.get_ylim())
|
130 |
+
ax.text(
|
131 |
+
0,
|
132 |
+
0,
|
133 |
+
title,
|
134 |
+
fontsize=15,
|
135 |
+
fontweight="extra bold",
|
136 |
+
horizontalalignment="center",
|
137 |
+
bbox={"boxstyle": "square,pad=0.3", "fc": "none"},
|
138 |
+
)
|
139 |
+
fig.tight_layout()
|
140 |
+
st.pyplot(fig)
|
141 |
+
else:
|
142 |
+
st.error("Invalid format. Please enter a dictionary of triads in the format {'triad_name': [(edge1), (edge2), ...]}.")
|
143 |
+
except Exception as e:
|
144 |
+
st.error(f"Error parsing input: {e}")
|
145 |
|
146 |
# Display the corresponding page based on sidebar option
|
147 |
if sidebar_option == "Graph: Triads":
|