shukdevdatta123 commited on
Commit
97613a3
·
verified ·
1 Parent(s): 00a8318

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -74,17 +74,24 @@ def display_weighted_graph():
74
  nodes = st.text_input("Enter nodes (comma-separated):", "a,b,c,d,e,f").split(',')
75
  nodes = [node.strip() for node in nodes]
76
 
77
- # Add a button to generate a new graph
 
 
 
 
 
 
 
 
 
78
  generate_button = st.button("Generate Graph")
79
 
80
  if generate_button:
81
  G_custom = nx.Graph()
82
 
83
- # Allow user to input weights for the edges between nodes
84
- for i in range(len(nodes)):
85
- for j in range(i + 1, len(nodes)):
86
- weight = st.number_input(f"Weight between {nodes[i]} and {nodes[j]}:", min_value=0.0, value=1.0)
87
- G_custom.add_edge(nodes[i], nodes[j], weight=weight)
88
 
89
  # Create layout for visualization
90
  pos = nx.spring_layout(G_custom, seed=7)
 
74
  nodes = st.text_input("Enter nodes (comma-separated):", "a,b,c,d,e,f").split(',')
75
  nodes = [node.strip() for node in nodes]
76
 
77
+ # Create a placeholder for weight inputs
78
+ weight_inputs = {}
79
+
80
+ # Collecting weight inputs for each edge
81
+ for i in range(len(nodes)):
82
+ for j in range(i + 1, len(nodes)):
83
+ weight = st.number_input(f"Weight between {nodes[i]} and {nodes[j]}:", min_value=0.0, value=1.0, key=f"weight_{nodes[i]}_{nodes[j]}")
84
+ weight_inputs[(nodes[i], nodes[j])] = weight
85
+
86
+ # Only show "Generate Graph" after weight inputs are made
87
  generate_button = st.button("Generate Graph")
88
 
89
  if generate_button:
90
  G_custom = nx.Graph()
91
 
92
+ # Add edges to the graph based on the input weights
93
+ for (node1, node2), weight in weight_inputs.items():
94
+ G_custom.add_edge(node1, node2, weight=weight)
 
 
95
 
96
  # Create layout for visualization
97
  pos = nx.spring_layout(G_custom, seed=7)