Update handler.py
Browse files- handler.py +6 -3
handler.py
CHANGED
@@ -31,9 +31,12 @@ class EndpointHandler:
|
|
31 |
|
32 |
predictions = []
|
33 |
for input in data["instances"]:
|
34 |
-
if
|
|
|
|
|
|
|
35 |
raise ValueError(
|
36 |
-
"The request body for each instance should contain both the `
|
37 |
)
|
38 |
|
39 |
try:
|
@@ -44,7 +47,7 @@ class EndpointHandler:
|
|
44 |
)
|
45 |
|
46 |
inputs = self.processor(
|
47 |
-
text=input["
|
48 |
).to(self.model.device)
|
49 |
input_len = inputs["input_ids"].shape[-1]
|
50 |
|
|
|
31 |
|
32 |
predictions = []
|
33 |
for input in data["instances"]:
|
34 |
+
if "prompt" in input:
|
35 |
+
input["text"] = input.pop("prompt")
|
36 |
+
|
37 |
+
if any(key not in input for key in {"text", "image_url"}):
|
38 |
raise ValueError(
|
39 |
+
"The request body for each instance should contain both the `text` and the `image_url` key with a valid image URL."
|
40 |
)
|
41 |
|
42 |
try:
|
|
|
47 |
)
|
48 |
|
49 |
inputs = self.processor(
|
50 |
+
text=input["text"], images=image, return_tensors="pt"
|
51 |
).to(self.model.device)
|
52 |
input_len = inputs["input_ids"].shape[-1]
|
53 |
|