push app
Browse files
app.py
CHANGED
|
@@ -103,19 +103,24 @@ if "img" in st.session_state:
|
|
| 103 |
new_coord = streamlit_image_coordinates(img_with_dots, key="click_img")
|
| 104 |
|
| 105 |
# If a new coordinate is received and it's not already in our list, add it and force a rerun.
|
| 106 |
-
if new_coord
|
|
|
|
|
|
|
| 107 |
for coord in st.session_state.coords_list:
|
| 108 |
existing = np.array([coord["x"], coord["y"]])
|
| 109 |
new = np.array([new_coord["x"], new_coord["y"]])
|
| 110 |
-
if
|
| 111 |
-
|
|
|
|
| 112 |
break
|
| 113 |
-
if
|
| 114 |
-
st.session_state.coords_list.remove(
|
|
|
|
|
|
|
| 115 |
else:
|
| 116 |
st.session_state.coords_list.append(new_coord)
|
| 117 |
-
|
| 118 |
-
|
| 119 |
|
| 120 |
st.write("Coordinates:", st.session_state.get("coords"))
|
| 121 |
|
|
|
|
| 103 |
new_coord = streamlit_image_coordinates(img_with_dots, key="click_img")
|
| 104 |
|
| 105 |
# If a new coordinate is received and it's not already in our list, add it and force a rerun.
|
| 106 |
+
if new_coord:
|
| 107 |
+
is_close = False
|
| 108 |
+
to_remove = None
|
| 109 |
for coord in st.session_state.coords_list:
|
| 110 |
existing = np.array([coord["x"], coord["y"]])
|
| 111 |
new = np.array([new_coord["x"], new_coord["y"]])
|
| 112 |
+
if np.linalg.norm(existing - new) < 10:
|
| 113 |
+
is_close = True
|
| 114 |
+
to_remove = coord
|
| 115 |
break
|
| 116 |
+
if is_close and to_remove is not None:
|
| 117 |
+
st.session_state.coords_list.remove(to_remove)
|
| 118 |
+
# Increment the widget key to reset the widget
|
| 119 |
+
st.session_state.widget_key += 1
|
| 120 |
else:
|
| 121 |
st.session_state.coords_list.append(new_coord)
|
| 122 |
+
# Also increment the key after a new addition if desired
|
| 123 |
+
st.session_state.widget_key += 1
|
| 124 |
|
| 125 |
st.write("Coordinates:", st.session_state.get("coords"))
|
| 126 |
|