Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -70,27 +70,27 @@ def display_weighted_graph():
|
|
70 |
st.pyplot(plt)
|
71 |
|
72 |
elif option == "Create your own":
|
73 |
-
# User can create their own graph
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
weight_inputs = {}
|
79 |
|
80 |
-
#
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
|
|
85 |
|
86 |
-
#
|
87 |
generate_button = st.button("Generate Graph")
|
88 |
|
89 |
if generate_button:
|
90 |
G_custom = nx.Graph()
|
91 |
|
92 |
-
# Add edges to the graph
|
93 |
-
for
|
94 |
G_custom.add_edge(node1, node2, weight=weight)
|
95 |
|
96 |
# Create layout for visualization
|
|
|
70 |
st.pyplot(plt)
|
71 |
|
72 |
elif option == "Create your own":
|
73 |
+
# User can create their own graph with edges and weights
|
74 |
+
edge_input = st.text_area(
|
75 |
+
"Enter edges with weights (format: node1,node2,weight;node1,node2,weight;...)",
|
76 |
+
"a,b,0.6;a,c,0.2;c,d,0.1;c,e,0.7;c,f,0.9;a,d,0.3"
|
77 |
+
)
|
|
|
78 |
|
79 |
+
# Parse the input string
|
80 |
+
edges = edge_input.split(";")
|
81 |
+
edge_list = []
|
82 |
+
for edge in edges:
|
83 |
+
node1, node2, weight = edge.split(",")
|
84 |
+
edge_list.append((node1.strip(), node2.strip(), float(weight.strip())))
|
85 |
|
86 |
+
# Add a button to generate the graph
|
87 |
generate_button = st.button("Generate Graph")
|
88 |
|
89 |
if generate_button:
|
90 |
G_custom = nx.Graph()
|
91 |
|
92 |
+
# Add edges to the graph
|
93 |
+
for node1, node2, weight in edge_list:
|
94 |
G_custom.add_edge(node1, node2, weight=weight)
|
95 |
|
96 |
# Create layout for visualization
|