shukdevdatta123 commited on
Commit
5478e5a
·
verified ·
1 Parent(s): 97613a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -14
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
- 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
 
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