mjohanes commited on
Commit
27251a9
·
1 Parent(s): 60e7d80
Files changed (1) hide show
  1. app.py +12 -7
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 and new_coord not in st.session_state.coords_list:
 
 
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 np.linalg.norm(existing - new) < 10:
111
- st.session_state.is_close = True
 
112
  break
113
- if st.session_state.is_close:
114
- st.session_state.coords_list.remove(coord)
 
 
115
  else:
116
  st.session_state.coords_list.append(new_coord)
117
- st.session_state.is_close = False
118
- st.rerun()
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