Spaces:
Sleeping
Sleeping
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 | |
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) | |