shukdevdatta123 commited on
Commit
331617f
·
verified ·
1 Parent(s): 8e7238b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -43
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=False,
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
- # 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
 
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":