0xnewton-superlore commited on
Commit ·
d318463
1
Parent(s): 7a7f986
refactor inference request structure
Browse files- handler.py +7 -5
handler.py
CHANGED
|
@@ -31,9 +31,10 @@ class EndpointHandler():
|
|
| 31 |
and, if both image and text lists are provided, calculate similarity scores between them.
|
| 32 |
|
| 33 |
Args:
|
| 34 |
-
data (Dict[str, Any]): A dictionary containing the following
|
| 35 |
-
- "
|
| 36 |
-
|
|
|
|
| 37 |
|
| 38 |
Returns:
|
| 39 |
Dict[str, list]: A dictionary containing the following keys:
|
|
@@ -42,8 +43,9 @@ class EndpointHandler():
|
|
| 42 |
- "similarity_scores" (List[List[float]]): A list of similarity scores between image and text embeddings.
|
| 43 |
Empty if either "image_list" or "text_list" is empty.
|
| 44 |
"""
|
| 45 |
-
|
| 46 |
-
|
|
|
|
| 47 |
|
| 48 |
image_features = self.get_image_embeddings(image_list) if len(image_list) > 0 else None
|
| 49 |
text_features = self.get_text_embeddings(text_list) if len(text_list) > 0 else None
|
|
|
|
| 31 |
and, if both image and text lists are provided, calculate similarity scores between them.
|
| 32 |
|
| 33 |
Args:
|
| 34 |
+
data (Dict[str, Any]): A dictionary containing the following key:
|
| 35 |
+
- "inputs" (Dict[str, list]): A dictionary containing the following keys:
|
| 36 |
+
- "image_list" (List[str]): A list of base64-encoded images.
|
| 37 |
+
- "text_list" (List[str]): A list of text strings.
|
| 38 |
|
| 39 |
Returns:
|
| 40 |
Dict[str, list]: A dictionary containing the following keys:
|
|
|
|
| 43 |
- "similarity_scores" (List[List[float]]): A list of similarity scores between image and text embeddings.
|
| 44 |
Empty if either "image_list" or "text_list" is empty.
|
| 45 |
"""
|
| 46 |
+
inputs = data.get("inputs", {})
|
| 47 |
+
image_list = inputs.get("image_list", []) # list of b64 images
|
| 48 |
+
text_list = inputs.get("text_list", []) # list of texts
|
| 49 |
|
| 50 |
image_features = self.get_image_embeddings(image_list) if len(image_list) > 0 else None
|
| 51 |
text_features = self.get_text_embeddings(text_list) if len(text_list) > 0 else None
|