File size: 2,850 Bytes
b16a5c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
631487a
2152801
b16a5c8
 
 
 
 
6a8790f
b16a5c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import pandas as pd
import numpy as np
import ast

from func import filter_by_ganre, recommendation



"""
# Умный поиск сериалов
"""

df = pd.read_csv('dataset.csv')
embeddings = np.loadtxt('embeddings.txt')
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)
    top_dict = recommendation(filt_ind, embeddings, text, n)
    st.write(f'<p style="font-family: Arial, sans-serif; font-size: 18px; text-align: center;"><strong>Всего подобранных \
         рекомендаций {len(top_dict)}</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
    )


# streamlit run shows.py