Spaces:
Runtime error
Runtime error
Update recommendation.py
Browse files- recommendation.py +2 -4
recommendation.py
CHANGED
@@ -3,13 +3,11 @@ from sentence_transformers import SentenceTransformer
|
|
3 |
from torchvision import transforms
|
4 |
from models.encoder import Encoder
|
5 |
from indexer import Indexer
|
6 |
-
import dotenv
|
7 |
import torch
|
8 |
import os
|
9 |
|
10 |
-
dotenv.load_dotenv()
|
11 |
|
12 |
-
model = SentenceTransformer('
|
13 |
|
14 |
encoder = Encoder()
|
15 |
encoder.load_state_dict(torch.load('./models/encoder.bin', map_location=torch.device('cpu')))
|
@@ -25,7 +23,7 @@ image_embedding_index = Indexer(latent_data)
|
|
25 |
|
26 |
def get_recommendations(image, title):
|
27 |
# title = [dataset[product_id]['title']]
|
28 |
-
title_embeds =
|
29 |
image = transforms.ToTensor()(image.convert("L"))
|
30 |
image_embeds = encoder(image).detach().numpy()
|
31 |
|
|
|
3 |
from torchvision import transforms
|
4 |
from models.encoder import Encoder
|
5 |
from indexer import Indexer
|
|
|
6 |
import torch
|
7 |
import os
|
8 |
|
|
|
9 |
|
10 |
+
model = SentenceTransformer('intfloat/multilingual-e5-base')
|
11 |
|
12 |
encoder = Encoder()
|
13 |
encoder.load_state_dict(torch.load('./models/encoder.bin', map_location=torch.device('cpu')))
|
|
|
23 |
|
24 |
def get_recommendations(image, title):
|
25 |
# title = [dataset[product_id]['title']]
|
26 |
+
title_embeds = model.encode(title, normalize_embeddings=True)
|
27 |
image = transforms.ToTensor()(image.convert("L"))
|
28 |
image_embeds = encoder(image).detach().numpy()
|
29 |
|