Update app.py
Browse files
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 |
-
#
|
| 84 |
-
edge_tuple =
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 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:
|