Update app.py
Browse files
app.py
CHANGED
|
@@ -94,46 +94,50 @@ def triads_graph():
|
|
| 94 |
elif graph_mode == "Create Your Own":
|
| 95 |
st.write("### Create Your Own Triads")
|
| 96 |
|
| 97 |
-
#
|
| 98 |
triad_input = st.text_area(
|
| 99 |
-
"Enter
|
| 100 |
-
value="[
|
| 101 |
)
|
| 102 |
|
| 103 |
-
# Try to evaluate the input as a
|
| 104 |
try:
|
| 105 |
-
|
| 106 |
-
if isinstance(
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
G
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
st.pyplot(fig)
|
| 135 |
else:
|
| 136 |
-
st.error("Invalid format. Please enter a
|
| 137 |
except Exception as e:
|
| 138 |
st.error(f"Error parsing input: {e}")
|
| 139 |
|
|
|
|
| 94 |
elif graph_mode == "Create Your Own":
|
| 95 |
st.write("### Create Your Own Triads")
|
| 96 |
|
| 97 |
+
# Input: Enter triads as a dictionary (e.g., {'triad_name': [(1, 2), (2, 1)]})
|
| 98 |
triad_input = st.text_area(
|
| 99 |
+
"Enter your triads in the format: {'triad_name': [(edge1), (edge2), ...]}",
|
| 100 |
+
value="{'003': [], '012': [(1, 2)]}"
|
| 101 |
)
|
| 102 |
|
| 103 |
+
# Try to evaluate the input as a dictionary of triads
|
| 104 |
try:
|
| 105 |
+
custom_triads = eval(triad_input)
|
| 106 |
+
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()):
|
| 107 |
+
fig, axes = plt.subplots(len(custom_triads), 1, figsize=(10, len(custom_triads) * 5))
|
| 108 |
+
if len(custom_triads) == 1: # Handle case where only one triad is entered
|
| 109 |
+
axes = [axes]
|
| 110 |
+
|
| 111 |
+
for (title, triad), ax in zip(custom_triads.items(), axes):
|
| 112 |
+
G = nx.DiGraph()
|
| 113 |
+
G.add_nodes_from([1, 2, 3])
|
| 114 |
+
G.add_edges_from(triad)
|
| 115 |
+
|
| 116 |
+
nx.draw_networkx(
|
| 117 |
+
G,
|
| 118 |
+
ax=ax,
|
| 119 |
+
with_labels=False,
|
| 120 |
+
node_color=["green"],
|
| 121 |
+
node_size=200,
|
| 122 |
+
arrowsize=20,
|
| 123 |
+
width=2,
|
| 124 |
+
pos=nx.planar_layout(G),
|
| 125 |
+
)
|
| 126 |
+
ax.set_xlim(val * 1.2 for val in ax.get_xlim())
|
| 127 |
+
ax.set_ylim(val * 1.2 for val in ax.get_ylim())
|
| 128 |
+
ax.text(
|
| 129 |
+
0,
|
| 130 |
+
0,
|
| 131 |
+
title,
|
| 132 |
+
fontsize=15,
|
| 133 |
+
fontweight="extra bold",
|
| 134 |
+
horizontalalignment="center",
|
| 135 |
+
bbox={"boxstyle": "square,pad=0.3", "fc": "none"},
|
| 136 |
+
)
|
| 137 |
+
fig.tight_layout()
|
| 138 |
st.pyplot(fig)
|
| 139 |
else:
|
| 140 |
+
st.error("Invalid format. Please enter a dictionary of triads in the format {'triad_name': [(edge1), (edge2), ...]}.")
|
| 141 |
except Exception as e:
|
| 142 |
st.error(f"Error parsing input: {e}")
|
| 143 |
|