amaye15
commited on
Commit
•
dbabaf1
1
Parent(s):
25a8604
Scores Implimented
Browse files- .gitignore +3 -1
- handler.py +17 -1
.gitignore
CHANGED
@@ -1,2 +1,4 @@
|
|
1 |
*.DS*
|
2 |
-
*__pycache__*
|
|
|
|
|
|
1 |
*.DS*
|
2 |
+
*__pycache__*
|
3 |
+
*.pdf
|
4 |
+
*.ipynb
|
handler.py
CHANGED
@@ -207,4 +207,20 @@ class EndpointHandler:
|
|
207 |
batch_text_embeddings = self._process_text_batch(batch_texts)
|
208 |
text_embeddings.extend(batch_text_embeddings)
|
209 |
|
210 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
batch_text_embeddings = self._process_text_batch(batch_texts)
|
208 |
text_embeddings.extend(batch_text_embeddings)
|
209 |
|
210 |
+
# Compute similarity scores if both image and text embeddings are available
|
211 |
+
scores = []
|
212 |
+
if image_embeddings and text_embeddings:
|
213 |
+
# Convert embeddings to tensors for scoring
|
214 |
+
image_embeddings_tensor = torch.tensor(image_embeddings).to(self.device)
|
215 |
+
text_embeddings_tensor = torch.tensor(text_embeddings).to(self.device)
|
216 |
+
|
217 |
+
with torch.no_grad():
|
218 |
+
scores = (
|
219 |
+
self.processor.score_multi_vector(
|
220 |
+
text_embeddings_tensor, image_embeddings_tensor
|
221 |
+
)
|
222 |
+
.cpu()
|
223 |
+
.tolist()
|
224 |
+
)
|
225 |
+
|
226 |
+
return {"image": image_embeddings, "text": text_embeddings, "scores": scores}
|