ChirathD commited on
Commit
a328bcd
1 Parent(s): 915e711

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +11 -4
handler.py CHANGED
@@ -13,7 +13,7 @@ from peft import PeftModel, PeftConfig
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,12 +50,19 @@ class EndpointHandler():
50
  image_io = io.BytesIO(image_bytes)
51
  image = Image.open(image_io)
52
 
53
- inputs = self.processor(images=image, return_tensors="pt")
 
54
  pixel_values = inputs.pixel_values
55
 
56
- generated_ids = self.model.generate(pixel_values=pixel_values, max_length=25)
57
  generated_caption = self.processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
58
- print(generated_caption)
 
 
 
 
 
 
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