Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -105,31 +105,30 @@ def process(image):
|
|
105 |
orig_image = image
|
106 |
w,h = orig_im_size = orig_image.size
|
107 |
image = resize_image(orig_image)
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
#
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
#
|
124 |
-
|
125 |
-
|
126 |
-
#
|
127 |
-
|
128 |
-
|
129 |
-
#
|
130 |
-
|
131 |
-
|
132 |
-
# return image
|
133 |
|
134 |
|
135 |
title = """<h1 style="text-align: center;">Product description generator</h1>"""
|
|
|
105 |
orig_image = image
|
106 |
w,h = orig_im_size = orig_image.size
|
107 |
image = resize_image(orig_image)
|
108 |
+
im_np = np.array(image)
|
109 |
+
im_tensor = torch.tensor(im_np, dtype=torch.float32).permute(2,0,1)
|
110 |
+
im_tensor = torch.unsqueeze(im_tensor,0)
|
111 |
+
im_tensor = torch.divide(im_tensor,255.0)
|
112 |
+
im_tensor = normalize(im_tensor,[0.5,0.5,0.5],[1.0,1.0,1.0])
|
113 |
+
if torch.cuda.is_available():
|
114 |
+
im_tensor=im_tensor.cuda()
|
115 |
+
|
116 |
+
#inference
|
117 |
+
result=net(im_tensor)
|
118 |
+
# post process
|
119 |
+
result = torch.squeeze(F.interpolate(result[0][0], size=(h,w), mode='bilinear') ,0)
|
120 |
+
ma = torch.max(result)
|
121 |
+
mi = torch.min(result)
|
122 |
+
result = (result-mi)/(ma-mi)
|
123 |
+
# image to pil
|
124 |
+
im_array = (result*255).cpu().data.numpy().astype(np.uint8)
|
125 |
+
pil_im = Image.fromarray(np.squeeze(im_array))
|
126 |
+
# paste the mask on the original image
|
127 |
+
new_im = Image.new("RGBA", pil_im.size, (0,0,0,0))
|
128 |
+
new_im.paste(orig_image, mask=pil_im)
|
129 |
+
# new_orig_image = orig_image.convert('RGBA')
|
130 |
+
|
131 |
+
return image
|
|
|
132 |
|
133 |
|
134 |
title = """<h1 style="text-align: center;">Product description generator</h1>"""
|