adasdimchom
commited on
Commit
·
1347a75
1
Parent(s):
ba84673
Upload handler.py
Browse files- handler.py +7 -4
handler.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from transformers import Blip2Processor,
|
2 |
from typing import Dict, List, Any
|
3 |
from PIL import Image
|
4 |
from transformers import pipeline
|
@@ -14,9 +14,12 @@ class EndpointHandler():
|
|
14 |
# pseudo:
|
15 |
# self.model= load_model(path)
|
16 |
#self.processor = Blip2Processor.from_pretrained(path)
|
17 |
-
self.pipeline = pipeline(model = path)
|
|
|
18 |
self.device = "cuda" if torch.cuda.is_available() else "cpu"
|
19 |
-
|
|
|
|
|
20 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
21 |
"""
|
22 |
data args:
|
@@ -33,4 +36,4 @@ class EndpointHandler():
|
|
33 |
#generated_ids = self.pipeline(**inputs)
|
34 |
#generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0].strip()
|
35 |
|
36 |
-
return image_url
|
|
|
1 |
+
from transformers import Blip2Processor, Blip2Model
|
2 |
from typing import Dict, List, Any
|
3 |
from PIL import Image
|
4 |
from transformers import pipeline
|
|
|
14 |
# pseudo:
|
15 |
# self.model= load_model(path)
|
16 |
#self.processor = Blip2Processor.from_pretrained(path)
|
17 |
+
#self.pipeline = pipeline(model = path)
|
18 |
+
self.path = path
|
19 |
self.device = "cuda" if torch.cuda.is_available() else "cpu"
|
20 |
+
#self.processor = Blip2Processor.from_pretrained(path)
|
21 |
+
#self.model = Blip2Model.from_pretrained(path, torch_dtype=torch.float16)
|
22 |
+
|
23 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
24 |
"""
|
25 |
data args:
|
|
|
36 |
#generated_ids = self.pipeline(**inputs)
|
37 |
#generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0].strip()
|
38 |
|
39 |
+
return image_url, self.path, self.device
|