Abdulrahman1989 commited on
Commit
1d126ec
·
1 Parent(s): bba3a5a
Files changed (1) hide show
  1. Image3DProcessor.py +5 -1
Image3DProcessor.py CHANGED
@@ -11,6 +11,7 @@ from PIL import Image
11
  import rembg
12
  from omegaconf import OmegaConf
13
  from huggingface_hub import hf_hub_download
 
14
  from utils.app_utils import (
15
  remove_background,
16
  resize_foreground,
@@ -41,6 +42,10 @@ class Image3DProcessor:
41
  self.model.eval()
42
 
43
  def preprocess(self, input_image, preprocess_background=True, foreground_ratio=0.65):
 
 
 
 
44
  rembg_session = rembg.new_session()
45
  if preprocess_background:
46
  image = input_image.convert("RGB")
@@ -93,4 +98,3 @@ class Image3DProcessor:
93
  loop_renders.append(torch.clamp(rendered_image * 255, 0.0, 255.0).detach().permute(1, 2, 0).cpu().numpy().astype(np.uint8))
94
 
95
  return mesh_path, video_path
96
-
 
11
  import rembg
12
  from omegaconf import OmegaConf
13
  from huggingface_hub import hf_hub_download
14
+ from io import BytesIO
15
  from utils.app_utils import (
16
  remove_background,
17
  resize_foreground,
 
42
  self.model.eval()
43
 
44
  def preprocess(self, input_image, preprocess_background=True, foreground_ratio=0.65):
45
+ # Convert bytes to PIL Image if necessary
46
+ if isinstance(input_image, bytes):
47
+ input_image = Image.open(BytesIO(input_image))
48
+
49
  rembg_session = rembg.new_session()
50
  if preprocess_background:
51
  image = input_image.convert("RGB")
 
98
  loop_renders.append(torch.clamp(rendered_image * 255, 0.0, 255.0).detach().permute(1, 2, 0).cpu().numpy().astype(np.uint8))
99
 
100
  return mesh_path, video_path