thoth-AI commited on
Commit
d6460d1
·
1 Parent(s): c99069e

Updated handler.py

Browse files
Files changed (1) hide show
  1. handler.py +5 -5
handler.py CHANGED
@@ -7,7 +7,7 @@ from io import BytesIO
7
  import torch
8
  import os
9
 
10
- device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
11
 
12
  class EndpointHandler:
13
  def __init__(self, path=""):
@@ -15,8 +15,7 @@ class EndpointHandler:
15
 
16
  self.processor = Blip2Processor.from_pretrained("Salesforce/blip2-opt-2.7b")
17
  self.model = Blip2ForConditionalGeneration.from_pretrained("Salesforce/blip2-opt-2.7b", device_map="auto")
18
- self.model.eval()
19
- self.model = self.model.to("cuda")
20
 
21
 
22
  def __call__(self, data: Any) -> Dict[str, Any]:
@@ -28,9 +27,10 @@ class EndpointHandler:
28
  A :obj:`dict`:. The object returned should be a dict of one list like {"captions": ["A hugging face at the office"]} containing :
29
  - "caption": A string corresponding to the generated caption.
30
  """
31
-
32
  inputs = data.pop("inputs", data)
33
- parameters = data.pop("parameters", {})
 
34
 
35
  raw_images = Image.open(BytesIO(inputs))
36
 
 
7
  import torch
8
  import os
9
 
10
+
11
 
12
  class EndpointHandler:
13
  def __init__(self, path=""):
 
15
 
16
  self.processor = Blip2Processor.from_pretrained("Salesforce/blip2-opt-2.7b")
17
  self.model = Blip2ForConditionalGeneration.from_pretrained("Salesforce/blip2-opt-2.7b", device_map="auto")
18
+
 
19
 
20
 
21
  def __call__(self, data: Any) -> Dict[str, Any]:
 
27
  A :obj:`dict`:. The object returned should be a dict of one list like {"captions": ["A hugging face at the office"]} containing :
28
  - "caption": A string corresponding to the generated caption.
29
  """
30
+
31
  inputs = data.pop("inputs", data)
32
+ # parameters = data.pop("parameters", {})
33
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
34
 
35
  raw_images = Image.open(BytesIO(inputs))
36