push app
Browse files
app.py
CHANGED
|
@@ -85,10 +85,6 @@ if picture is not None:
|
|
| 85 |
st.session_state.img = img # save the processed image
|
| 86 |
# st.session_state.coords_list = []
|
| 87 |
|
| 88 |
-
# Ensure we have a widget_key in session state
|
| 89 |
-
if "widget_key" not in st.session_state:
|
| 90 |
-
st.session_state.widget_key = 0
|
| 91 |
-
|
| 92 |
if "img" in st.session_state:
|
| 93 |
img = st.session_state.img
|
| 94 |
|
|
@@ -104,27 +100,22 @@ if "img" in st.session_state:
|
|
| 104 |
draw.ellipse((cx - 5, cy - 5, cx + 5, cy + 5), fill="red")
|
| 105 |
|
| 106 |
# Use the interactive component as the display canvas, showing the image with all dots.
|
| 107 |
-
new_coord = streamlit_image_coordinates(img_with_dots, key=
|
| 108 |
|
| 109 |
# If a new coordinate is received and it's not already in our list, add it and force a rerun.
|
| 110 |
-
if new_coord:
|
| 111 |
-
is_close = False
|
| 112 |
-
to_remove = None
|
| 113 |
for coord in st.session_state.coords_list:
|
| 114 |
existing = np.array([coord["x"], coord["y"]])
|
| 115 |
new = np.array([new_coord["x"], new_coord["y"]])
|
| 116 |
-
if
|
| 117 |
-
is_close = True
|
| 118 |
-
to_remove = coord
|
| 119 |
break
|
| 120 |
-
if is_close
|
| 121 |
-
st.session_state.coords_list.remove(
|
| 122 |
-
# Increment the widget key to reset the widget
|
| 123 |
-
st.session_state.widget_key += 1
|
| 124 |
else:
|
| 125 |
st.session_state.coords_list.append(new_coord)
|
| 126 |
-
|
| 127 |
-
st.session_state.widget_key += 1
|
| 128 |
|
| 129 |
st.write("Coordinates:", st.session_state.get("coords"))
|
| 130 |
|
|
|
|
| 85 |
st.session_state.img = img # save the processed image
|
| 86 |
# st.session_state.coords_list = []
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
if "img" in st.session_state:
|
| 89 |
img = st.session_state.img
|
| 90 |
|
|
|
|
| 100 |
draw.ellipse((cx - 5, cy - 5, cx + 5, cy + 5), fill="red")
|
| 101 |
|
| 102 |
# Use the interactive component as the display canvas, showing the image with all dots.
|
| 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 |
+
st.session_state.is_close = False
|
|
|
|
| 108 |
for coord in st.session_state.coords_list:
|
| 109 |
existing = np.array([coord["x"], coord["y"]])
|
| 110 |
new = np.array([new_coord["x"], new_coord["y"]])
|
| 111 |
+
if np.linalg.norm(existing - new) < 10:
|
| 112 |
+
st.session_state.is_close = True
|
|
|
|
| 113 |
break
|
| 114 |
+
if st.session_state.is_close:
|
| 115 |
+
st.session_state.coords_list.remove(coord)
|
|
|
|
|
|
|
| 116 |
else:
|
| 117 |
st.session_state.coords_list.append(new_coord)
|
| 118 |
+
st.rerun()
|
|
|
|
| 119 |
|
| 120 |
st.write("Coordinates:", st.session_state.get("coords"))
|
| 121 |
|