ZhengPeng7 commited on
Commit
fb60ce9
·
1 Parent(s): c98f37f

Add the deployment option.

Browse files
Files changed (2) hide show
  1. handler.py +2 -12
  2. requirements.txt +2 -0
handler.py CHANGED
@@ -9,6 +9,7 @@ from PIL import Image
9
  import torch
10
  from torchvision import transforms
11
  from transformers import AutoModelForImageSegmentation
 
12
 
13
  torch.set_float32_matmul_precision(["high", "highest"][0])
14
 
@@ -104,18 +105,7 @@ class EndpointHandler():
104
  A :obj:`list` | `dict`: will be serialized and returned
105
  """
106
  print('data["inputs"] = ', data["inputs"])
107
- image_src = data["inputs"]
108
- if isinstance(image_src, str):
109
- if os.path.isfile(image_src):
110
- image_ori = Image.open(image_src)
111
- else:
112
- response = requests.get(image_src)
113
- image_data = BytesIO(response.content)
114
- image_ori = Image.open(image_data)
115
- else:
116
- image_ori = Image.fromarray(image_src)
117
-
118
- image = image_ori.convert('RGB')
119
  # Preprocess the image
120
  image_preprocessor = ImagePreprocessor(resolution=tuple(resolution))
121
  image_proc = image_preprocessor.proc(image)
 
9
  import torch
10
  from torchvision import transforms
11
  from transformers import AutoModelForImageSegmentation
12
+ from loadimg import load_img
13
 
14
  torch.set_float32_matmul_precision(["high", "highest"][0])
15
 
 
105
  A :obj:`list` | `dict`: will be serialized and returned
106
  """
107
  print('data["inputs"] = ', data["inputs"])
108
+ image = load_img(data["inputs"]).convert("RGB")
 
 
 
 
 
 
 
 
 
 
 
109
  # Preprocess the image
110
  image_preprocessor = ImagePreprocessor(resolution=tuple(resolution))
111
  image_proc = image_preprocessor.proc(image)
requirements.txt CHANGED
@@ -16,3 +16,5 @@ prettytable
16
  transformers
17
  huggingface-hub>0.25
18
  accelerate
 
 
 
16
  transformers
17
  huggingface-hub>0.25
18
  accelerate
19
+
20
+ loadimg