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

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +4 -4
handler.py CHANGED
@@ -9,17 +9,17 @@ class EndpointHandler():
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
- model = AutoModelForCausalLM.from_pretrained("microsoft/Florence-2-large", torch_dtype=torch_dtype, trust_remote_code=True).to(device)
13
- processor = AutoProcessor.from_pretrained("microsoft/Florence-2-large", trust_remote_code=True)
14
 
15
 
16
  def predict_image(self, url, prompt):
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 = processor(text=prompt, images=image, return_tensors="pt").to(device, torch_dtype)
21
 
22
- generated_ids = model.generate(
23
  input_ids=inputs["input_ids"],
24
  pixel_values=inputs["pixel_values"],
25
  max_new_tokens=4096,
 
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)
14
 
15
 
16
  def predict_image(self, url, prompt):
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"],
24
  pixel_values=inputs["pixel_values"],
25
  max_new_tokens=4096,