shukdevdatta123 commited on
Commit
1e58db6
·
verified ·
1 Parent(s): c2ba324

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -25
app.py CHANGED
@@ -70,38 +70,20 @@ def algorithms_cycle_detection():
70
  st.write("### Create Your Own Graph")
71
 
72
  # Input for creating custom graph
73
- edges_input = st.text_area("Enter directed edges (e.g., (1, 2), (2, 3), (3, 4), (4, 2)):").strip()
74
 
75
  if st.button("Generate Graph"):
76
  if edges_input:
77
  try:
78
- edges = []
79
- # Ensure correct formatting of the input string
80
- edge_strings = edges_input.split("),")
81
- for edge_str in edge_strings:
82
- edge_str = edge_str.strip()
83
- if edge_str:
84
- # Handle the case where the edge might be missing a closing parenthesis
85
- if edge_str[-1] != ")":
86
- edge_str += ")"
87
- # Remove the opening and closing parentheses
88
- edge_tuple = edge_str.strip("()").split(",")
89
- if len(edge_tuple) == 2:
90
- try:
91
- # Safely convert to integers and add the edge
92
- edge_tuple = tuple(map(int, edge_tuple))
93
- edges.append(edge_tuple)
94
- except ValueError:
95
- st.error(f"Invalid edge format: {edge_str}")
96
- return
97
-
98
- if edges:
99
- # Create the graph
100
  G = nx.DiGraph(edges)
101
  st.write("Custom Graph:", G.edges())
102
  plot_cycle_detection(G)
103
- else:
104
- st.error("No valid edges provided.")
105
  except Exception as e:
106
  st.error(f"Error creating the graph: {e}")
107
  else:
 
70
  st.write("### Create Your Own Graph")
71
 
72
  # Input for creating custom graph
73
+ edges_input = st.text_area("Enter directed edges (e.g., (1, 2), (2, 3), (3, 4), (4, 2)):")
74
 
75
  if st.button("Generate Graph"):
76
  if edges_input:
77
  try:
78
+ # Parse the input edges
79
+ edges = [tuple(map(int, edge.strip()[1:-1].split(","))) for edge in edges_input.split(",")]
80
+ if not edges:
81
+ st.error("No valid edges provided.")
82
+ else:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  G = nx.DiGraph(edges)
84
  st.write("Custom Graph:", G.edges())
85
  plot_cycle_detection(G)
86
+
 
87
  except Exception as e:
88
  st.error(f"Error creating the graph: {e}")
89
  else: