fix and log inputs
Browse filesFiles changed (3)
6 unmodified lines789101011121312 unmodified lines262728293029303132333435363738394041424041424344454647484950515253545556576 unmodified lines
class EndpointHandler: def __init__(self, path=""): def __init__(self): self.processor = LlavaNextProcessor.from_pretrained("llava-hf/llava-v1.6-mistral-7b-hf")
12 unmodified lines def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]: """ data args: text (:obj: `str`) files (:obj: `list`) - List of URLs to images inputs (:obj: `dict`) Return: A :obj:`list` | `dict`: will be serialized and returned """ # get inputs inputs = data.pop("inputs", data)
if not inputs: return f"Inputs not in payload got {data.keys()}" # get additional date field0 prompt = inputs.pop("prompt", None) image_url = inputs.pop("image", None)
print(image_url) print(prompt)
if image_url is None: return "You need to upload an image URL for LLaVA to work."
if prompt is None: 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." if not self.model: return "Model was not initialized" if not self.processor: return "Processor was not initialized" # Create a temporary directory with TemporaryDirectory() as tmpdirname: # Download the image1234513 unmodified lines19202121222324252627import osimport jsonimport requestsfrom dotenv import load_dotenv
13 unmodified lines response = requests.post( URL, headers=headers, json=payload json=json.dumps(payload) ) print(response) return response.json()
def test_local(payload):__pycache__/handler.cpython-311.pyc
handler.py+15-6
test_inference_endpoint.py+3-1