Spaces:
Sleeping
Sleeping
File size: 3,717 Bytes
a18e62f 9f79d71 3394e57 9f79d71 a18e62f 9f79d71 a18e62f 3394e57 a18e62f 9f79d71 a18e62f 9f79d71 a18e62f 9f79d71 a18e62f 9f79d71 a18e62f 9f79d71 a18e62f 9f79d71 a18e62f 9f79d71 a18e62f 9f79d71 a18e62f 9f79d71 a18e62f 9f79d71 a18e62f 9f79d71 a18e62f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
import streamlit as st
import pandas as pd
import numpy as np
import ast
import faiss
from data.func import filter_by_ganre, embed_user
"""
# Умный поиск сериалов
"""
df = pd.read_csv('data/dataset.csv')
embeddings = np.load('data/embeddings_main.npy')
index = faiss.read_index('data/faiss_index_main.index')
df['ganres'] = df['ganres'].apply(lambda x: ast.literal_eval(x))
st.write(f'<p style="font-family: Arial, sans-serif; font-size: 24px; ">Количество сериалов, \
предоставляемых сервисом {len(df)}</p>', unsafe_allow_html=True)
ganres_lst = sorted(['драма', 'документальный', 'биография', 'комедия', 'фэнтези', 'приключения', 'для детей', 'мультсериалы',
'мелодрама', 'боевик', 'детектив', 'фантастика', 'триллер', 'семейный', 'криминал', 'исторический', 'музыкальные',
'мистика', 'аниме', 'ужасы', 'спорт', 'скетч-шоу', 'военный', 'для взрослых', 'вестерн'])
st.sidebar.header('Панель инструментов :gear:')
choice_g = st.sidebar.multiselect("Выберите жанры", options=ganres_lst)
n = st.sidebar.selectbox("Количество отображаемых элементов на странице", options=[5, 10, 15])
# col3, col4 = st.columns([5,2])
# with col3:
text = st.text_input('Введите описание для рекомендации')
# with col4:
button = st.button('Отправить запрос', type="primary")
if text and button:
if len(choice_g) == 0:
choice_g = ganres_lst
filt_ind = filter_by_ganre(df, choice_g)
user_emb = embed_user(filt_ind, embeddings, text, n)
_, sorted_indices = index.search(user_emb.reshape(1, -1), n)
st.write(f'<p style="font-family: Arial, sans-serif; font-size: 18px; text-align: center;"><strong>Всего подобранных \
рекомендаций {len(sorted_indices[0])}</strong></p>', unsafe_allow_html=True)
st.write('\n')
# Отображение изображений и названий
# for ind, sim in top_dict.items():
# col1, col2 = st.columns([3, 4])
# with col1:
# st.image(df['poster'][ind], width=300)
# with col2:
# st.write(f"***Название:*** {df['title'][ind]}")
# st.write(f"***Жанр:*** {', '.join(df['ganres'][ind])}")
# st.write(f"***Описание:*** {df['description'][ind]}")
# similarity = round(sim, 4)
# st.write(f"***Cosine Similarity : {similarity}***")
# st.write(f"***Ссылка на фильм : {df['url'][ind]}***")
# st.markdown(
# "<hr style='border: 2px solid #000; margin-top: 10px; margin-bottom: 10px;'>",
# unsafe_allow_html=True
# )
for ind in sorted_indices[0]:
col1, col2 = st.columns([3, 4])
with col1:
st.image(df['poster'][ind], width=300)
with col2:
st.write(f"***Название:*** {df['title'][ind]}")
st.write(f"***Жанр:*** {', '.join(df['ganres'][ind])}")
st.write(f"***Описание:*** {df['description'][ind]}")
# similarity = round(sim, 4)
# st.write(f"***Cosine Similarity : {similarity}***")
st.write(f"***Ссылка на фильм : {df['url'][ind]}***")
st.markdown(
"<hr style='border: 2px solid #000; margin-top: 10px; margin-bottom: 10px;'>",
unsafe_allow_html=True
) |