Update app.py
Browse files
app.py
CHANGED
|
@@ -76,12 +76,15 @@ def algorithms_cycle_detection():
|
|
| 76 |
if edges_input:
|
| 77 |
try:
|
| 78 |
edges = []
|
| 79 |
-
#
|
| 80 |
-
edge_strings = edges_input.split(",")
|
| 81 |
for edge_str in edge_strings:
|
| 82 |
edge_str = edge_str.strip()
|
| 83 |
-
if edge_str:
|
| 84 |
-
#
|
|
|
|
|
|
|
|
|
|
| 85 |
edge_tuple = edge_str.strip("()").split(",")
|
| 86 |
if len(edge_tuple) == 2:
|
| 87 |
try:
|
|
@@ -89,7 +92,7 @@ def algorithms_cycle_detection():
|
|
| 89 |
edge_tuple = tuple(map(int, edge_tuple))
|
| 90 |
edges.append(edge_tuple)
|
| 91 |
except ValueError:
|
| 92 |
-
st.error(f"Invalid edge format: {edge_str}
|
| 93 |
return
|
| 94 |
|
| 95 |
if edges:
|
|
@@ -98,7 +101,7 @@ def algorithms_cycle_detection():
|
|
| 98 |
st.write("Custom Graph:", G.edges())
|
| 99 |
plot_cycle_detection(G)
|
| 100 |
else:
|
| 101 |
-
st.error("No valid edges provided.
|
| 102 |
except Exception as e:
|
| 103 |
st.error(f"Error creating the graph: {e}")
|
| 104 |
else:
|
|
|
|
| 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:
|
|
|
|
| 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:
|
|
|
|
| 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:
|