Ashoka74 commited on
Commit
94aa06b
1 Parent(s): d4804f6

Update app_3.py

Browse files
Files changed (1) hide show
  1. app_3.py +16 -14
app_3.py CHANGED
@@ -995,6 +995,8 @@ def use_orientation(selected_image:gr.SelectData):
995
  @torch.inference_mode
996
  def process_image(input_image, input_text):
997
  """Main processing function for the Gradio interface"""
 
 
998
 
999
  if isinstance(input_image, Image.Image):
1000
  input_image = np.array(input_image)
@@ -1117,17 +1119,17 @@ def process_image(input_image, input_text):
1117
  # resize the longer side to H * 0.9
1118
  H, W, _ = image_center.shape
1119
  if H > W:
1120
- W = int(W * (height * 0.9) / H)
1121
- H = int(height * 0.9)
1122
  else:
1123
- H = int(H * (width * 0.9) / W)
1124
- W = int(width * 0.9)
1125
 
1126
  image_center = np.array(Image.fromarray(image_center).resize((W, H)))
1127
  # pad to H, W
1128
- start_h = (height - H) // 2
1129
- start_w = (width - W) // 2
1130
- image = np.zeros((height, width, 4), dtype=np.uint8)
1131
  image[start_h : start_h + H, start_w : start_w + W] = image_center
1132
  image = image.astype(np.float32) / 255.0
1133
  image = image[:, :, :3] * image[:, :, 3:4] + (1 - image[:, :, 3:4]) * 0.5
@@ -1280,17 +1282,17 @@ def process_image(input_image, input_text):
1280
  # resize the longer side to H * 0.9
1281
  H, W, _ = image_center.shape
1282
  if H > W:
1283
- W = int(W * (height * 0.9) / H)
1284
- H = int(height * 0.9)
1285
  else:
1286
- H = int(H * (width * 0.9) / W)
1287
- W = int(width * 0.9)
1288
 
1289
  image_center = np.array(Image.fromarray(image_center).resize((W, H)))
1290
  # pad to H, W
1291
- start_h = (height - H) // 2
1292
- start_w = (width - W) // 2
1293
- image = np.zeros((height, width, 4), dtype=np.uint8)
1294
  image[start_h : start_h + H, start_w : start_w + W] = image_center
1295
  image = image.astype(np.float32) / 255.0
1296
  image = image[:, :, :3] * image[:, :, 3:4] + (1 - image[:, :, 3:4]) * 0.5
 
995
  @torch.inference_mode
996
  def process_image(input_image, input_text):
997
  """Main processing function for the Gradio interface"""
998
+
999
+
1000
 
1001
  if isinstance(input_image, Image.Image):
1002
  input_image = np.array(input_image)
 
1119
  # resize the longer side to H * 0.9
1120
  H, W, _ = image_center.shape
1121
  if H > W:
1122
+ W = int(W * (HEIGHT * 0.9) / H)
1123
+ H = int(HEIGHT * 0.9)
1124
  else:
1125
+ H = int(H * (WIDTH * 0.9) / W)
1126
+ W = int(WIDTH * 0.9)
1127
 
1128
  image_center = np.array(Image.fromarray(image_center).resize((W, H)))
1129
  # pad to H, W
1130
+ start_h = (HEIGHT - H) // 2
1131
+ start_w = (WIDTH - W) // 2
1132
+ image = np.zeros((HEIGHT, WIDTH, 4), dtype=np.uint8)
1133
  image[start_h : start_h + H, start_w : start_w + W] = image_center
1134
  image = image.astype(np.float32) / 255.0
1135
  image = image[:, :, :3] * image[:, :, 3:4] + (1 - image[:, :, 3:4]) * 0.5
 
1282
  # resize the longer side to H * 0.9
1283
  H, W, _ = image_center.shape
1284
  if H > W:
1285
+ W = int(W * (HEIGHT * 0.9) / H)
1286
+ H = int(HEIGHT * 0.9)
1287
  else:
1288
+ H = int(H * (WIDTH * 0.9) / W)
1289
+ W = int(WIDTH * 0.9)
1290
 
1291
  image_center = np.array(Image.fromarray(image_center).resize((W, H)))
1292
  # pad to H, W
1293
+ start_h = (HEIGHT - H) // 2
1294
+ start_w = (WIDTH - W) // 2
1295
+ image = np.zeros((HEIGHT, WIDTH, 4), dtype=np.uint8)
1296
  image[start_h : start_h + H, start_w : start_w + W] = image_center
1297
  image = image.astype(np.float32) / 255.0
1298
  image = image[:, :, :3] * image[:, :, 3:4] + (1 - image[:, :, 3:4]) * 0.5