Update handler.py
Browse files- handler.py +2 -2
handler.py
CHANGED
@@ -19,16 +19,16 @@ class EndpointHandler():
|
|
19 |
|
20 |
def __call__(self, data: Dict[list, Any]):
|
21 |
parameters = data.pop("inputs", data)
|
22 |
-
|
23 |
outputs = []
|
24 |
print(parameters)
|
|
|
25 |
for link in parameters:
|
26 |
try:
|
27 |
# Fetch image from URL
|
28 |
response = requests.get(link, stream=True)
|
29 |
response.raise_for_status() # Raise an exception for 4xx or 5xx status codes
|
30 |
raw_image = Image.open(response.raw)
|
31 |
-
|
32 |
# Process image and generate output
|
33 |
inputs = self.processor(prompt, raw_image, return_tensors='pt').to(0, torch.float32)
|
34 |
output = self.model.generate(**inputs, max_new_tokens=200, do_sample=False)
|
|
|
19 |
|
20 |
def __call__(self, data: Dict[list, Any]):
|
21 |
parameters = data.pop("inputs", data)
|
22 |
+
givenprompt = data.pop("prompt", data)
|
23 |
outputs = []
|
24 |
print(parameters)
|
25 |
+
prompt = f"USER: <image>\n{givenprompt}?\nASSISTANT:"
|
26 |
for link in parameters:
|
27 |
try:
|
28 |
# Fetch image from URL
|
29 |
response = requests.get(link, stream=True)
|
30 |
response.raise_for_status() # Raise an exception for 4xx or 5xx status codes
|
31 |
raw_image = Image.open(response.raw)
|
|
|
32 |
# Process image and generate output
|
33 |
inputs = self.processor(prompt, raw_image, return_tensors='pt').to(0, torch.float32)
|
34 |
output = self.model.generate(**inputs, max_new_tokens=200, do_sample=False)
|