Update handler.py
Browse files- handler.py +13 -12
handler.py
CHANGED
@@ -5,17 +5,18 @@ import requests
|
|
5 |
|
6 |
class EndpointHandler():
|
7 |
def __init__(self, path=""):
|
8 |
-
|
|
|
9 |
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
outputs = self.pipeline(image, prompt=prompt, generate_kwargs={"max_new_tokens": 200})
|
19 |
-
totalarr.append(outputs)
|
20 |
-
return totalarr
|
21 |
-
|
|
|
5 |
|
6 |
class EndpointHandler():
|
7 |
def __init__(self, path=""):
|
8 |
+
print("init")
|
9 |
+
# self.pipeline = pipeline("image-to-text", model=path)
|
10 |
|
11 |
+
def __call__(self, data: Dict[str, Any]):
|
12 |
+
totalarr = []
|
13 |
+
inputs = data.pop("inputs", [])
|
14 |
+
prompt_base = data.pop("prompt", "")
|
15 |
|
16 |
+
for link in inputs:
|
17 |
+
image = Image.open(requests.get(link, stream=True).raw)
|
18 |
+
prompt = f"USER: <image>\n{prompt_base}.Answer in one word\nASSISTANT:"
|
19 |
+
outputs = self.pipeline(image, prompt=prompt, generate_kwargs={"max_new_tokens": 200})
|
20 |
+
totalarr.append(outputs)
|
21 |
+
|
22 |
+
return totalarr
|
|
|
|
|
|
|
|