Drazcat-AI commited on
Commit
d627c65
·
verified ·
1 Parent(s): 5ce696e

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +3 -3
handler.py CHANGED
@@ -6,8 +6,8 @@ from transformers import AutoProcessor, AutoModelForCausalLM
6
 
7
  class EndpointHandler():
8
  def __init__(self, path=""):
9
- device = "cuda:0" if torch.cuda.is_available() else "cpu"
10
- torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
11
 
12
  self.model = AutoModelForCausalLM.from_pretrained("microsoft/Florence-2-large", torch_dtype=torch_dtype, trust_remote_code=True).to(device)
13
  self.processor = AutoProcessor.from_pretrained("microsoft/Florence-2-large", trust_remote_code=True)
@@ -17,7 +17,7 @@ class EndpointHandler():
17
  url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true"
18
  image = Image.open(requests.get(url, stream=True).raw)
19
 
20
- inputs = self.processor(text=prompt, images=image, return_tensors="pt").to(device, torch_dtype)
21
 
22
  generated_ids = self.model.generate(
23
  input_ids=inputs["input_ids"],
 
6
 
7
  class EndpointHandler():
8
  def __init__(self, path=""):
9
+ self.device = "cuda:0" if torch.cuda.is_available() else "cpu"
10
+ self.torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
11
 
12
  self.model = AutoModelForCausalLM.from_pretrained("microsoft/Florence-2-large", torch_dtype=torch_dtype, trust_remote_code=True).to(device)
13
  self.processor = AutoProcessor.from_pretrained("microsoft/Florence-2-large", trust_remote_code=True)
 
17
  url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true"
18
  image = Image.open(requests.get(url, stream=True).raw)
19
 
20
+ inputs = self.processor(text=prompt, images=image, return_tensors="pt").to(self.device, self.torch_dtype)
21
 
22
  generated_ids = self.model.generate(
23
  input_ids=inputs["input_ids"],