Spaces:
Running
Running
Commit
·
960b239
1
Parent(s):
076742e
Update app.py
Browse files
app.py
CHANGED
@@ -223,7 +223,7 @@ def model_process(input): #image, mask):
|
|
223 |
# {'image': '/tmp/tmp8mn9xw93.png', 'mask': '/tmp/tmpn5ars4te.png'}
|
224 |
# input = request.files
|
225 |
# RGB
|
226 |
-
origin_image_bytes =
|
227 |
print(f'origin_image_bytes = ', type(origin_image_bytes), len(origin_image_bytes))
|
228 |
|
229 |
image, alpha_channel = load_img(origin_image_bytes)
|
@@ -274,9 +274,9 @@ def model_process(input): #image, mask):
|
|
274 |
logger.info(f"Resized image shape: {image.shape} / {type(image)}")
|
275 |
print(f"Resized image shape: {image.shape} / {image[250][250]}")
|
276 |
|
277 |
-
mask,
|
278 |
mask = resize_max_size(mask, size_limit=size_limit, interpolation=interpolation)
|
279 |
-
print(f"mask image shape: {mask.shape} / {type(mask)} / {mask[250][250]}")
|
280 |
|
281 |
start = time.time()
|
282 |
res_np_img = model(image, mask, config)
|
@@ -331,20 +331,22 @@ transform = transforms.Compose([
|
|
331 |
])
|
332 |
'''
|
333 |
|
334 |
-
def read_content(file_path: str)
|
335 |
"""read the content of target file
|
336 |
"""
|
337 |
-
with open(file_path, '
|
338 |
content = f.read()
|
339 |
|
340 |
return content
|
341 |
|
342 |
def predict(input):
|
343 |
print(f'liuyz_0_', input)
|
|
|
344 |
image_np = np.array(input["image"])
|
345 |
print(f'image_np = {image_np.shape}')
|
346 |
mask_np = np.array(input["mask"])
|
347 |
-
print(f'mask_np = {mask_np.shape}')
|
|
|
348 |
'''
|
349 |
image = dict["image"] # .convert("RGB") #.resize((512, 512))
|
350 |
# target_size = (init_image.shape[0], init_image.shape[1])
|
@@ -353,11 +355,11 @@ def predict(input):
|
|
353 |
print(f'liuyz_3_', image.convert("RGB").resize((512, 512)).shape)
|
354 |
# mask = dict["mask"] # .convert("RGB") #.resize((512, 512))
|
355 |
'''
|
356 |
-
|
357 |
|
358 |
# output = mask #output.images[0]
|
359 |
# output = pipe(prompt = prompt, image=init_image, mask_image=mask,guidance_scale=7.5)
|
360 |
-
output = input["mask"]
|
361 |
return output #, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
362 |
|
363 |
print(f'liuyz_500_here_')
|
|
|
223 |
# {'image': '/tmp/tmp8mn9xw93.png', 'mask': '/tmp/tmpn5ars4te.png'}
|
224 |
# input = request.files
|
225 |
# RGB
|
226 |
+
origin_image_bytes = read_content(input["image"])
|
227 |
print(f'origin_image_bytes = ', type(origin_image_bytes), len(origin_image_bytes))
|
228 |
|
229 |
image, alpha_channel = load_img(origin_image_bytes)
|
|
|
274 |
logger.info(f"Resized image shape: {image.shape} / {type(image)}")
|
275 |
print(f"Resized image shape: {image.shape} / {image[250][250]}")
|
276 |
|
277 |
+
mask, alpha_channel = load_img(read_content(input["mask"]), gray=True)
|
278 |
mask = resize_max_size(mask, size_limit=size_limit, interpolation=interpolation)
|
279 |
+
print(f"mask image shape: {mask.shape} / {type(mask)} / {mask[250][250]} / {alpha_channel}")
|
280 |
|
281 |
start = time.time()
|
282 |
res_np_img = model(image, mask, config)
|
|
|
331 |
])
|
332 |
'''
|
333 |
|
334 |
+
def read_content(file_path: str):
|
335 |
"""read the content of target file
|
336 |
"""
|
337 |
+
with open(file_path, 'rb', encoding='utf-8') as f:
|
338 |
content = f.read()
|
339 |
|
340 |
return content
|
341 |
|
342 |
def predict(input):
|
343 |
print(f'liuyz_0_', input)
|
344 |
+
'''
|
345 |
image_np = np.array(input["image"])
|
346 |
print(f'image_np = {image_np.shape}')
|
347 |
mask_np = np.array(input["mask"])
|
348 |
+
print(f'mask_np = {mask_np.shape}')
|
349 |
+
'''
|
350 |
'''
|
351 |
image = dict["image"] # .convert("RGB") #.resize((512, 512))
|
352 |
# target_size = (init_image.shape[0], init_image.shape[1])
|
|
|
355 |
print(f'liuyz_3_', image.convert("RGB").resize((512, 512)).shape)
|
356 |
# mask = dict["mask"] # .convert("RGB") #.resize((512, 512))
|
357 |
'''
|
358 |
+
output = model_process(input) # dict["image"], dict["mask"])
|
359 |
|
360 |
# output = mask #output.images[0]
|
361 |
# output = pipe(prompt = prompt, image=init_image, mask_image=mask,guidance_scale=7.5)
|
362 |
+
# output = input["mask"]
|
363 |
return output #, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
364 |
|
365 |
print(f'liuyz_500_here_')
|