mjohanes commited on
Commit
56cc275
·
1 Parent(s): e7e965c
Files changed (1) hide show
  1. app.py +19 -15
app.py CHANGED
@@ -177,18 +177,22 @@ else:
177
  # Prompt input for inpainting
178
  prompt = st.text_input("Prompt for inpainting (describe what should replace the selected area):")
179
 
180
- # Only proceed when a point is selected and prompt is provided
181
- # if coords and prompt:
182
- # cx, cy = int(coords['x']), int(coords['y'])
183
- # st.write("Generating mask with FastSAM...")
184
- # results = fastsam_model(img, points=[[cx, cy]], labels=[1])
185
- # mask_data = results[0].masks.data[0]
186
- # mask_array = mask_data.cpu().numpy()
187
- # mask_image = Image.fromarray((mask_array * 255).astype(np.uint8))
188
-
189
- # st.write("Running Stable Diffusion Inpainting...")
190
- # result = sd_pipe(prompt=prompt, image=img, mask_image=mask_image).images[0]
191
-
192
- # # Finally, update the same canvas with the inpainted image
193
- # with canvas.container():
194
- # canvas.image(result, caption="Inpainted Image", use_container_width=True)
 
 
 
 
 
177
  # Prompt input for inpainting
178
  prompt = st.text_input("Prompt for inpainting (describe what should replace the selected area):")
179
 
180
+ # --- 4) INPAINTING LOGIC ---
181
+ prompt = st.text_input("Prompt for inpainting (describe what should replace the selected area):")
182
+
183
+ # If there's a prompt and we have at least one mask from the combined points, do inpainting
184
+ if prompt and combined_mask_img is not None:
185
+ if st.button("Run Inpainting"):
186
+ with st.spinner("Inpainting..."):
187
+ # Run Stable Diffusion Inpainting on the entire combined mask
188
+ inpainted_img = sd_pipe(
189
+ prompt=prompt,
190
+ image=img,
191
+ mask_image=combined_mask_img
192
+ ).images[0]
193
+
194
+ # Update the session image to the newly inpainted result
195
+ st.session_state.img = inpainted_img
196
+ # Optionally reset the points or keep them
197
+ st.session_state.coords_list = []
198
+ st.rerun()