JiminHeo commited on
Commit
18be823
·
1 Parent(s): 25e9acb
Files changed (1) hide show
  1. app.py +4 -8
app.py CHANGED
@@ -20,6 +20,7 @@ st.title("Mask Your Own Inpaint")
20
  def load_images():
21
  """Loads images from an NPZ file only once to cache."""
22
  data = np.load("data/sflckr_all_images.npz")
 
23
  images = data["images"]
24
  return images
25
 
@@ -32,13 +33,6 @@ images = load_images()
32
  if st.button("Random Pick"):
33
  st.session_state.random_idx = random.randint(0, images.shape[0] - 1)
34
 
35
- def make_square(img, target_size=300):
36
- """Pads and resizes the image to a square."""
37
- size = max(img.size)
38
- background = Image.new("RGB", (size, size), (255, 255, 255))
39
- offset = ((size - img.size[0]) // 2, (size - img.size[1]) // 2)
40
- background.paste(img, offset)
41
- return background.resize((target_size, target_size))
42
 
43
  def run_inpainting(random_idx, mask_array, image_queue, sampling_queue):
44
  """Starts inpainting and sends images to the queue."""
@@ -48,7 +42,6 @@ def run_inpainting(random_idx, mask_array, image_queue, sampling_queue):
48
  if st.session_state.random_idx is not None:
49
  img_array = images[st.session_state.random_idx]
50
  img_pil = Image.fromarray(img_array)
51
- img_pil = make_square(img_pil, target_size=512) # Resized to 512x512
52
 
53
  # Set up drawing canvas and display columns
54
  col1, col2 = st.columns(2)
@@ -76,10 +69,13 @@ if st.session_state.random_idx is not None:
76
  st.write("Masked Image")
77
  st.image(binary_mask, caption="Binary Mask", width=300)
78
 
 
79
  mask_image = Image.fromarray(binary_mask)
80
  mask_array = 255 - np.array(mask_image)
81
  mask_array = np.expand_dims(mask_array, axis=(0, 1))
82
 
 
 
83
  # Inpaint button action
84
  if st.button("inpaint"):
85
  st.write("Please wait...")
 
20
  def load_images():
21
  """Loads images from an NPZ file only once to cache."""
22
  data = np.load("data/sflckr_all_images.npz")
23
+
24
  images = data["images"]
25
  return images
26
 
 
33
  if st.button("Random Pick"):
34
  st.session_state.random_idx = random.randint(0, images.shape[0] - 1)
35
 
 
 
 
 
 
 
 
36
 
37
  def run_inpainting(random_idx, mask_array, image_queue, sampling_queue):
38
  """Starts inpainting and sends images to the queue."""
 
42
  if st.session_state.random_idx is not None:
43
  img_array = images[st.session_state.random_idx]
44
  img_pil = Image.fromarray(img_array)
 
45
 
46
  # Set up drawing canvas and display columns
47
  col1, col2 = st.columns(2)
 
69
  st.write("Masked Image")
70
  st.image(binary_mask, caption="Binary Mask", width=300)
71
 
72
+
73
  mask_image = Image.fromarray(binary_mask)
74
  mask_array = 255 - np.array(mask_image)
75
  mask_array = np.expand_dims(mask_array, axis=(0, 1))
76
 
77
+
78
+
79
  # Inpaint button action
80
  if st.button("inpaint"):
81
  st.write("Please wait...")