Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -70,20 +70,38 @@ 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)):")
|
74 |
|
75 |
if st.button("Generate Graph"):
|
76 |
if edges_input:
|
77 |
try:
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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:
|
|
|
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:
|