fix and log inputs
Browse files- __pycache__/handler.cpython-311.pyc +0 -0
- handler.py +15 -6
- test_inference_endpoint.py +3 -1
__pycache__/handler.cpython-311.pyc
CHANGED
Binary files a/__pycache__/handler.cpython-311.pyc and b/__pycache__/handler.cpython-311.pyc differ
|
|
handler.py
CHANGED
@@ -7,7 +7,7 @@ import requests
|
|
7 |
|
8 |
|
9 |
class EndpointHandler:
|
10 |
-
def __init__(self
|
11 |
self.processor = LlavaNextProcessor.from_pretrained("llava-hf/llava-v1.6-mistral-7b-hf")
|
12 |
|
13 |
|
@@ -26,23 +26,32 @@ class EndpointHandler:
|
|
26 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
27 |
"""
|
28 |
data args:
|
29 |
-
|
30 |
-
files (:obj: `list`) - List of URLs to images
|
31 |
Return:
|
32 |
A :obj:`list` | `dict`: will be serialized and returned
|
33 |
"""
|
34 |
# get inputs
|
35 |
inputs = data.pop("inputs", data)
|
|
|
|
|
|
|
|
|
36 |
# get additional date field0
|
37 |
prompt = inputs.pop("prompt", None)
|
38 |
image_url = inputs.pop("image", None)
|
39 |
|
40 |
-
print(image_url)
|
41 |
-
print(prompt)
|
42 |
-
|
43 |
if image_url is None:
|
44 |
return "You need to upload an image URL for LLaVA to work."
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
# Create a temporary directory
|
47 |
with TemporaryDirectory() as tmpdirname:
|
48 |
# Download the image
|
|
|
7 |
|
8 |
|
9 |
class EndpointHandler:
|
10 |
+
def __init__(self):
|
11 |
self.processor = LlavaNextProcessor.from_pretrained("llava-hf/llava-v1.6-mistral-7b-hf")
|
12 |
|
13 |
|
|
|
26 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
27 |
"""
|
28 |
data args:
|
29 |
+
inputs (:obj: `dict`)
|
|
|
30 |
Return:
|
31 |
A :obj:`list` | `dict`: will be serialized and returned
|
32 |
"""
|
33 |
# get inputs
|
34 |
inputs = data.pop("inputs", data)
|
35 |
+
|
36 |
+
if not inputs:
|
37 |
+
return f"Inputs not in payload got {data.keys()}"
|
38 |
+
|
39 |
# get additional date field0
|
40 |
prompt = inputs.pop("prompt", None)
|
41 |
image_url = inputs.pop("image", None)
|
42 |
|
|
|
|
|
|
|
43 |
if image_url is None:
|
44 |
return "You need to upload an image URL for LLaVA to work."
|
45 |
|
46 |
+
if prompt is None:
|
47 |
+
prompt = "Can you describe this picture focusing on specifics visual artifacts and ambiance (objects, colors, person, athmosphere..). Please stay concise only output keywords and concepts detected."
|
48 |
+
|
49 |
+
if not self.model:
|
50 |
+
return "Model was not initialized"
|
51 |
+
|
52 |
+
if not self.processor:
|
53 |
+
return "Processor was not initialized"
|
54 |
+
|
55 |
# Create a temporary directory
|
56 |
with TemporaryDirectory() as tmpdirname:
|
57 |
# Download the image
|
test_inference_endpoint.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import os
|
|
|
2 |
import requests
|
3 |
from dotenv import load_dotenv
|
4 |
|
@@ -18,8 +19,9 @@ def call(payload):
|
|
18 |
response = requests.post(
|
19 |
URL,
|
20 |
headers=headers,
|
21 |
-
json=payload
|
22 |
)
|
|
|
23 |
return response.json()
|
24 |
|
25 |
def test_local(payload):
|
|
|
1 |
import os
|
2 |
+
import json
|
3 |
import requests
|
4 |
from dotenv import load_dotenv
|
5 |
|
|
|
19 |
response = requests.post(
|
20 |
URL,
|
21 |
headers=headers,
|
22 |
+
json=json.dumps(payload)
|
23 |
)
|
24 |
+
print(response)
|
25 |
return response.json()
|
26 |
|
27 |
def test_local(payload):
|