Spaces:
Sleeping
Sleeping
HaggiVaggi
commited on
Commit
•
630ecc3
1
Parent(s):
51c3be1
Update app.py
Browse files
app.py
CHANGED
@@ -68,16 +68,18 @@ if page == "какая-то еще":
|
|
68 |
embeddings = pd.read_pickle('embeddings.pkl')
|
69 |
user_input = st.text_area('Введите описание фильма')
|
70 |
input_embedding = encode_description(user_input)
|
71 |
-
|
|
|
72 |
|
|
|
|
|
73 |
|
74 |
-
|
75 |
-
|
76 |
|
77 |
-
|
|
|
78 |
sorted_indices = similarity_scores.argsort()[::-1]
|
79 |
-
|
80 |
-
# Используйте индексы для извлечения строк из DataFrame
|
81 |
recs = df2.iloc[sorted_indices[:10]].reset_index(drop=True)
|
82 |
recs.index = recs.index + 1
|
83 |
st.write(recs[['movie_title', 'description']])
|
|
|
68 |
embeddings = pd.read_pickle('embeddings.pkl')
|
69 |
user_input = st.text_area('Введите описание фильма')
|
70 |
input_embedding = encode_description(user_input)
|
71 |
+
def parse_tensor_string(tensor_string):
|
72 |
+
return torch.tensor(ast.literal_eval(tensor_string))
|
73 |
|
74 |
+
# Преобразование колонки description_embedding в embeddings_tensor
|
75 |
+
df2['embeddings_tensor'] = df2['description_embedding'].apply(parse_tensor_string)
|
76 |
|
77 |
+
# Объединение тензоров в один большой тензор
|
78 |
+
embeddings_tensor = torch.stack(df2['embeddings_tensor'].tolist())
|
79 |
|
80 |
+
# Ваш оставшийся код остается без изменений
|
81 |
+
similarity_scores = cosine_similarity(input_embedding.view(1, -1).detach().numpy(), embeddings_tensor.reshape(embeddings_tensor.shape[0], -1))[0]
|
82 |
sorted_indices = similarity_scores.argsort()[::-1]
|
|
|
|
|
83 |
recs = df2.iloc[sorted_indices[:10]].reset_index(drop=True)
|
84 |
recs.index = recs.index + 1
|
85 |
st.write(recs[['movie_title', 'description']])
|