File size: 1,933 Bytes
7576ded
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import pandas as pd
import random as rd
import webbrowser as wb
from find import find_similar,df
st.set_page_config(
    page_title="Умный поиск книг",
    page_icon="path/to/favicon.ico",
    layout="wide",
    initial_sidebar_state="expanded"
)

df
st.title('Умный поиск книг')
form = st.form(key='search_form')
input=form.text_input('Введите поисковый запрос')

# if 'clicked' not in st.session_state:
#     st.session_state.clicked = False
#df= pd.read_csv('books_booksle.csv')

items_per_page=form.number_input('Количество книг на странице',min_value=1,max_value=10,value=5)
search_but=form.form_submit_button('Искать')


# if search_but:
#     st.session_state.clicked = True

@st.cache_data(experimental_allow_widgets=True)
def books_show(books,sims):
    col=[]
    for i in range(len(books)):
        col.append(st.columns([0.2,0.8]))
        '---'
        
        url=books.iloc[i,0]#'page_url'][i]
        col[i][0].image(books['image_url'][i],width=200)
        col[i][0].markdown('<a href={url} target="_blank">Ссылка на книгу</a>', unsafe_allow_html=True)
        col[i][0].markdown(f'**Степень похожести:** {books["sims"][i]:.4f}')
        #col[i][0].button('Купить',key=books['page_url'][i],on_click=lambda: wb.open_new_tab(books['page_url'][i]))
        col[i][1].markdown('## '+ f"{books['title'][i]}")
        col[i][1].markdown('**Автор:** ' +books['author'][i])
        col[i][1].markdown('**Аннотация:** '  +books['annotation'][i])    
if search_but:
    sims,books_idx=find_similar(input)
    #sims
    books=df.copy()
    books['sims']=sims
    books=books.iloc[books_idx].iloc[:items_per_page]
    #books=books.iloc[:items_per_page]
    #books=df.iloc[books_idx]
    #[:items_per_page]
    #sims
    books
    #books['sims'][0]
    books_show(books,sims)