fix and log inputs
Browse filesFiles changed (3)
6 unmodified lines7891011121312 unmodified lines26272829303132333435363738394041424344454647486 unmodified linesclass EndpointHandler:def __init__(self, path=""):self.processor = LlavaNextProcessor.from_pretrained("llava-hf/llava-v1.6-mistral-7b-hf")12 unmodified linesdef __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:"""data args:text (:obj: `str`)files (:obj: `list`) - List of URLs to imagesReturn:A :obj:`list` | `dict`: will be serialized and returned"""# get inputsinputs = data.pop("inputs", data)# get additional date field0prompt = 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."# Create a temporary directorywith TemporaryDirectory() as tmpdirname:# Download the image6 unmodified lines7891011121312 unmodified lines26272829303132333435363738394041424344454647484950515253545556576 unmodified linesclass EndpointHandler:def __init__(self):self.processor = LlavaNextProcessor.from_pretrained("llava-hf/llava-v1.6-mistral-7b-hf")12 unmodified linesdef __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:"""data args:inputs (:obj: `dict`)Return:A :obj:`list` | `dict`: will be serialized and returned"""# get inputsinputs = data.pop("inputs", data)if not inputs:return f"Inputs not in payload got {data.keys()}"# get additional date field0prompt = inputs.pop("prompt", None)image_url = inputs.pop("image", None)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 directorywith TemporaryDirectory() as tmpdirname:# Download the image
123413 unmodified lines1819202122232425import osimport requestsfrom dotenv import load_dotenv13 unmodified linesresponse = requests.post(URL,headers=headers,json=payload)return response.json()def test_local(payload):1234513 unmodified lines192021222324252627import osimport jsonimport requestsfrom dotenv import load_dotenv13 unmodified linesresponse = requests.post(URL,headers=headers,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