mjohanes commited on
Commit
bbbe3f7
·
1 Parent(s): 40bc7ea
Files changed (1) hide show
  1. app.py +21 -16
app.py CHANGED
@@ -83,29 +83,34 @@ if picture is not None:
83
  img = picture.copy()
84
  img = crop_resize_image(img, size=512)
85
  st.session_state.img = img # save the processed image
 
86
 
87
  if "img" in st.session_state:
88
  img = st.session_state.img
89
 
90
- # If we have coordinates stored, create an image with a red dot overlay.
91
- if "coords" in st.session_state:
92
- cx, cy = int(st.session_state.coords["x"]), int(st.session_state.coords["y"])
93
- img_with_dot = img.copy()
94
- draw = ImageDraw.Draw(img_with_dot)
95
- draw.ellipse((cx-5, cy-5, cx+5, cy+5), fill="red")
96
- display_img = img_with_dot
97
- else:
98
- display_img = img
99
-
100
- # Call the streamlit_image_coordinates component with our display image.
101
- coords = streamlit_image_coordinates(display_img, key="click_img")
102
-
103
- # If new coordinates are returned and differ from what we have stored, update them and rerun.
104
- if coords and st.session_state.get("coords") != coords:
105
- st.session_state.coords = coords
 
106
  st.rerun()
107
 
108
  st.write("Coordinates:", st.session_state.get("coords"))
 
 
 
109
  # Prompt input for inpainting
110
  prompt = st.text_input("Prompt for inpainting (describe what should replace the selected area):")
111
 
 
83
  img = picture.copy()
84
  img = crop_resize_image(img, size=512)
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
 
91
+ # Initialize the coordinates list if it doesn't exist.
92
+ if "coords_list" not in st.session_state:
93
+ st.session_state.coords_list = []
94
+
95
+ # Create a copy of the image and draw red dots for every stored coordinate.
96
+ img_with_dots = img.copy()
97
+ draw = ImageDraw.Draw(img_with_dots)
98
+ for coord in st.session_state.coords_list:
99
+ cx, cy = int(coord["x"]), int(coord["y"])
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.coords_list.append(new_coord)
108
  st.rerun()
109
 
110
  st.write("Coordinates:", st.session_state.get("coords"))
111
+
112
+
113
+
114
  # Prompt input for inpainting
115
  prompt = st.text_input("Prompt for inpainting (describe what should replace the selected area):")
116