botteaap commited on
Commit
a19a224
1 Parent(s): 49d9d73

Initial import

Browse files
Files changed (3) hide show
  1. .gitignore +1 -0
  2. handler.py +25 -0
  3. requirements.txt +2 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ venv
handler.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Dict, List, Any
2
+ import torch
3
+ from transformers import BitsAndBytesConfig, pipeline
4
+
5
+ device = "cuda" if torch.cuda.is_available() else "cpu"
6
+
7
+
8
+ class EndpointHandler():
9
+ def __init__(self, path=""):
10
+ quantization_config = BitsAndBytesConfig(
11
+ load_in_4bit=True,
12
+ bnb_4bit_compute_dtype=torch.float16
13
+ )
14
+ # self.pipeline = pipeline("image-to-text", model="llava-hf/llava-1.5-7b-hf",
15
+ # model_kwargs={"quantization_config": quantization_config})
16
+
17
+ def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
18
+ print(data)
19
+ inputs = data.pop("inputs", data)
20
+ image = data.pop("image", None)
21
+ prompt = data.pop("prompt", None)
22
+ # outputs = self.pipeline(image, prompt=prompt, generate_kwargs={
23
+ # "max_new_tokens": 200})
24
+ # return {"caption": outputs[0]["generated_text"]}
25
+ return {"image": image, "prompt": prompt}
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ transformers==4.38.2
2
+ bitsandbytes