shukdevdatta123 commited on
Commit
ee3aaf3
·
verified ·
1 Parent(s): 3a770e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -11
app.py CHANGED
@@ -75,21 +75,25 @@ def algorithms_cycle_detection():
75
  if st.button("Generate Graph"):
76
  if edges_input:
77
  try:
78
- # Parse the input edges, ensuring the format is correct
79
  edges = []
 
80
  for edge in edges_input.split(","):
81
  edge = edge.strip()
82
  if edge: # Ensure the string is not empty
83
- # Convert string to tuple (e.g., "(1, 2)" -> (1, 2))
84
- edge_tuple = tuple(map(int, edge[1:-1].split(",")))
85
- edges.append(edge_tuple)
86
-
87
- # Create the graph
88
- G = nx.DiGraph(edges)
89
-
90
- st.write("Custom Graph:", G.edges())
91
- plot_cycle_detection(G)
92
-
 
 
 
 
93
  except Exception as e:
94
  st.error(f"Error creating the graph: {e}")
95
  else:
 
75
  if st.button("Generate Graph"):
76
  if edges_input:
77
  try:
 
78
  edges = []
79
+ # Split input by commas and process each edge
80
  for edge in edges_input.split(","):
81
  edge = edge.strip()
82
  if edge: # Ensure the string is not empty
83
+ # Remove spaces and extra characters, and convert to tuple
84
+ edge_tuple = edge.strip("()").split(",")
85
+ if len(edge_tuple) == 2:
86
+ # Safely convert to integers
87
+ edge_tuple = tuple(map(int, edge_tuple))
88
+ edges.append(edge_tuple)
89
+
90
+ if edges:
91
+ # Create the graph
92
+ G = nx.DiGraph(edges)
93
+ st.write("Custom Graph:", G.edges())
94
+ plot_cycle_detection(G)
95
+ else:
96
+ st.error("No valid edges provided.")
97
  except Exception as e:
98
  st.error(f"Error creating the graph: {e}")
99
  else: