Update handler.py
Browse files- handler.py +11 -4
handler.py
CHANGED
@@ -13,7 +13,7 @@ from peft import PeftModel, PeftConfig
|
|
13 |
|
14 |
# -
|
15 |
|
16 |
-
|
17 |
|
18 |
class EndpointHandler():
|
19 |
def __init__(self, path=""):
|
@@ -50,12 +50,19 @@ class EndpointHandler():
|
|
50 |
image_io = io.BytesIO(image_bytes)
|
51 |
image = Image.open(image_io)
|
52 |
|
53 |
-
|
|
|
54 |
pixel_values = inputs.pixel_values
|
55 |
|
56 |
-
generated_ids = self.model.generate(pixel_values=pixel_values, max_length=
|
57 |
generated_caption = self.processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
# raw_images = [Image.open(BytesIO(_img)) for _img in inputs]
|
61 |
|
|
|
13 |
|
14 |
# -
|
15 |
|
16 |
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
17 |
|
18 |
class EndpointHandler():
|
19 |
def __init__(self, path=""):
|
|
|
50 |
image_io = io.BytesIO(image_bytes)
|
51 |
image = Image.open(image_io)
|
52 |
|
53 |
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
54 |
+
inputs = self.processor(images=image, return_tensors="pt").to(device, torch.float16)
|
55 |
pixel_values = inputs.pixel_values
|
56 |
|
57 |
+
generated_ids = self.model.generate(pixel_values=pixel_values, max_length=100)
|
58 |
generated_caption = self.processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
59 |
+
|
60 |
+
# device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
61 |
+
# inputs = processor(images=image, return_tensors="pt").to(device, torch.float16)
|
62 |
+
# pixel_values = inputs.pixel_values
|
63 |
+
|
64 |
+
# generated_ids = model.generate(pixel_values=pixel_values, max_length=100)
|
65 |
+
# generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
66 |
|
67 |
# raw_images = [Image.open(BytesIO(_img)) for _img in inputs]
|
68 |
|