tastelikefeet commited on
Commit
f089029
1 Parent(s): 7c8010b
Files changed (3) hide show
  1. __pycache__/versions.cpython-311.pyc +0 -0
  2. app.py +17 -6
  3. css/style.css +1 -1
__pycache__/versions.cpython-311.pyc ADDED
Binary file (221 Bytes). View file
 
app.py CHANGED
@@ -53,9 +53,11 @@ for idx, name in enumerate(files):
53
  temp = os.path.join(os.path.dirname(__file__), img, name)
54
  showcases.append(temp)
55
 
56
- def process(input_image, original_image, original_mask, selected_points, source_background, prompt, face_prompt):
57
- if original_image is None or original_mask is None or len(selected_points)==0:
58
- raise gr.Error('Please upload the input image and select the object you want to keep by clicking the mouse.')
 
 
59
 
60
  # load example image
61
  if isinstance(original_image, int):
@@ -63,7 +65,11 @@ def process(input_image, original_image, original_mask, selected_points, source_
63
  original_image = cv2.imread(image_name)
64
  original_image = cv2.cvtColor(original_image, cv2.COLOR_BGR2RGB)
65
 
66
- original_mask = np.clip(255 - original_mask, 0, 255).astype(np.uint8)
 
 
 
 
67
 
68
  request_id = str(uuid.uuid4())
69
  input_image_url = upload_np_2_oss(original_image, request_id+".png")
@@ -134,7 +140,7 @@ with block:
134
  with gr.Row(equal_height=True):
135
  gr.Markdown("""
136
  - ⭐️ <b>step1:</b>Upload or select one image from Example
137
- - ⭐️ <b>step2:</b>Click on Input-image to select the object to be retained
138
  - ⭐️ <b>step3:</b>Input prompt or reference image (highly-recommended) for generating new contents
139
  - ⭐️ <b>step4:</b>Click Run button
140
  """)
@@ -159,6 +165,9 @@ with block:
159
  with gr.Tabs(elem_classes=["feedback1"]):
160
  with gr.TabItem("Reference Image (Optional)"):
161
  source_background = gr.Image(type="numpy", label="Background Image")
 
 
 
162
 
163
  face_prompt = gr.Textbox(label="Face Prompt", value='good face, beautiful face, best quality')
164
  with gr.Column():
@@ -187,6 +196,8 @@ with block:
187
  # image upload is too slow
188
  if min(img.shape[0], img.shape[1]) > 896:
189
  img = resize_image(img, 896)
 
 
190
  return img, img, [], None # when new image is uploaded, `selected_points` should be empty
191
 
192
  input_image.upload(
@@ -294,7 +305,7 @@ with block:
294
  [gallery_flag]
295
  )
296
 
297
- ips=[input_image, original_image, original_mask, selected_points, source_background, prompt, face_prompt]
298
  run_button.click(fn=process, inputs=ips, outputs=[result_gallery, request_id, gallery_flag])
299
 
300
 
 
53
  temp = os.path.join(os.path.dirname(__file__), img, name)
54
  showcases.append(temp)
55
 
56
+ def process(input_image, original_image, original_mask, input_mask, selected_points, source_background, prompt, face_prompt):
57
+ if original_image is None:
58
+ raise gr.Error('Please upload the input image')
59
+ if (original_mask is None or len(selected_points)==0) and input_mask is None:
60
+ raise gr.Error("Please click the region where you want to keep unchanged, or upload a white-black Mask image where white color indicates region to be retained.")
61
 
62
  # load example image
63
  if isinstance(original_image, int):
 
65
  original_image = cv2.imread(image_name)
66
  original_image = cv2.cvtColor(original_image, cv2.COLOR_BGR2RGB)
67
 
68
+ if input_mask is not None:
69
+ H,W=original_image.shape[:2]
70
+ original_mask = cv2.resize(input_mask, (W, H))
71
+ else:
72
+ original_mask = np.clip(255 - original_mask, 0, 255).astype(np.uint8)
73
 
74
  request_id = str(uuid.uuid4())
75
  input_image_url = upload_np_2_oss(original_image, request_id+".png")
 
140
  with gr.Row(equal_height=True):
141
  gr.Markdown("""
142
  - ⭐️ <b>step1:</b>Upload or select one image from Example
143
+ - ⭐️ <b>step2:</b>Click on Input-image to select the object to be retained (or upload a white-black Mask image, in which white color indicates the region you want to keep unchanged)
144
  - ⭐️ <b>step3:</b>Input prompt or reference image (highly-recommended) for generating new contents
145
  - ⭐️ <b>step4:</b>Click Run button
146
  """)
 
165
  with gr.Tabs(elem_classes=["feedback1"]):
166
  with gr.TabItem("Reference Image (Optional)"):
167
  source_background = gr.Image(type="numpy", label="Background Image")
168
+ with gr.Tabs(elem_classes=["feedback1"]):
169
+ with gr.TabItem("User-specified Mask Image (Optional)"):
170
+ input_mask = gr.Image(type="numpy", label="Mask Image")
171
 
172
  face_prompt = gr.Textbox(label="Face Prompt", value='good face, beautiful face, best quality')
173
  with gr.Column():
 
196
  # image upload is too slow
197
  if min(img.shape[0], img.shape[1]) > 896:
198
  img = resize_image(img, 896)
199
+ if max(img.shape[0], img.shape[1])*1.0/min(img.shape[0], img.shape[1])>2.0:
200
+ raise gr.Error('image aspect ratio cannot be larger than 2.0')
201
  return img, img, [], None # when new image is uploaded, `selected_points` should be empty
202
 
203
  input_image.upload(
 
305
  [gallery_flag]
306
  )
307
 
308
+ ips=[input_image, original_image, original_mask, input_mask, selected_points, source_background, prompt, face_prompt]
309
  run_button.click(fn=process, inputs=ips, outputs=[result_gallery, request_id, gallery_flag])
310
 
311
 
css/style.css CHANGED
@@ -39,7 +39,7 @@
39
  font-weight: bold;
40
  }
41
  #Image {
42
- width: 60%;
43
  margin:auto;
44
  }
45
  #ShowCase {
 
39
  font-weight: bold;
40
  }
41
  #Image {
42
+ width: 80%;
43
  margin:auto;
44
  }
45
  #ShowCase {