Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -70,13 +70,21 @@ 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 |
-
# Parse the input edges
|
79 |
-
edges = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
G = nx.DiGraph(edges)
|
81 |
|
82 |
st.write("Custom Graph:", G.edges())
|
|
|
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 |
+
# 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())
|