Spaces:
Sleeping
Sleeping
OverSide88
commited on
Commit
•
96d9a9d
1
Parent(s):
3d14a1f
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,8 @@ import faiss
|
|
7 |
from streamlit.errors import StreamlitAPIException
|
8 |
import urllib.parse
|
9 |
|
|
|
|
|
10 |
import os
|
11 |
os.environ['KMP_DUPLICATE_LIB_OK'] = 'TRUE'
|
12 |
|
@@ -41,6 +43,7 @@ embeddings_matrix = np.stack(embeddings)
|
|
41 |
index = faiss.IndexFlatIP(embeddings_matrix.shape[1])
|
42 |
index.add(embeddings_matrix)
|
43 |
|
|
|
44 |
# CSS стили для заднего фона
|
45 |
background_image = """
|
46 |
<style>
|
@@ -49,6 +52,7 @@ background_image = """
|
|
49 |
background-size: cover;
|
50 |
background-position: center;
|
51 |
background-repeat: no-repeat;
|
|
|
52 |
}
|
53 |
</style>
|
54 |
"""
|
@@ -56,7 +60,8 @@ background_image = """
|
|
56 |
# Вставляем CSS стили в приложение Streamlit
|
57 |
st.markdown(background_image, unsafe_allow_html=True)
|
58 |
|
59 |
-
|
|
|
60 |
transparent_title = """
|
61 |
<style>
|
62 |
.transparent-title {
|
@@ -64,7 +69,7 @@ transparent_title = """
|
|
64 |
padding: 10px;
|
65 |
border-radius: 5px;
|
66 |
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
|
67 |
-
color:
|
68 |
}
|
69 |
</style>
|
70 |
"""
|
@@ -76,7 +81,6 @@ transparent_box = """
|
|
76 |
padding: 10px;
|
77 |
border-radius: 5px;
|
78 |
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
|
79 |
-
color: black;
|
80 |
}
|
81 |
</style>
|
82 |
"""
|
@@ -93,6 +97,7 @@ text = st.text_input('Введите ваш запрос для поиска к
|
|
93 |
num_results = st.number_input('Количество результатов:', min_value=1, max_value=20, value=3)
|
94 |
recommend_button = st.button('Получить рекомендации')
|
95 |
|
|
|
96 |
if text and recommend_button: # Check if the user entered text and clicked the button
|
97 |
|
98 |
# Embed the query and search for nearest vectors using Faiss
|
@@ -119,14 +124,14 @@ if text and recommend_button: # Check if the user entered text and clicked the
|
|
119 |
st.write(e)
|
120 |
|
121 |
with col2:
|
122 |
-
# Выводим информацию о книге на прозрачном фоне
|
123 |
st.markdown(f"""
|
124 |
<div class="transparent-box">
|
125 |
<p><b>Название книги:</b> {books['title'][i]}</p>
|
126 |
<p><b>Автор:</b> {books['author'][i]}</p>
|
127 |
-
<p><b>Описание:</b>
|
128 |
<p><b>Оценка сходства:</b> {similarity_percent:.2f}%</p>
|
129 |
</div>
|
130 |
""", unsafe_allow_html=True)
|
131 |
|
132 |
-
st.write("---")
|
|
|
7 |
from streamlit.errors import StreamlitAPIException
|
8 |
import urllib.parse
|
9 |
|
10 |
+
|
11 |
+
|
12 |
import os
|
13 |
os.environ['KMP_DUPLICATE_LIB_OK'] = 'TRUE'
|
14 |
|
|
|
43 |
index = faiss.IndexFlatIP(embeddings_matrix.shape[1])
|
44 |
index.add(embeddings_matrix)
|
45 |
|
46 |
+
|
47 |
# CSS стили для заднего фона
|
48 |
background_image = """
|
49 |
<style>
|
|
|
52 |
background-size: cover;
|
53 |
background-position: center;
|
54 |
background-repeat: no-repeat;
|
55 |
+
color: blue;
|
56 |
}
|
57 |
</style>
|
58 |
"""
|
|
|
60 |
# Вставляем CSS стили в приложение Streamlit
|
61 |
st.markdown(background_image, unsafe_allow_html=True)
|
62 |
|
63 |
+
|
64 |
+
# Вставляем CSS стили для окошка с прозрачным фоном
|
65 |
transparent_title = """
|
66 |
<style>
|
67 |
.transparent-title {
|
|
|
69 |
padding: 10px;
|
70 |
border-radius: 5px;
|
71 |
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
|
72 |
+
color: blue;
|
73 |
}
|
74 |
</style>
|
75 |
"""
|
|
|
81 |
padding: 10px;
|
82 |
border-radius: 5px;
|
83 |
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
|
|
|
84 |
}
|
85 |
</style>
|
86 |
"""
|
|
|
97 |
num_results = st.number_input('Количество результатов:', min_value=1, max_value=20, value=3)
|
98 |
recommend_button = st.button('Получить рекомендации')
|
99 |
|
100 |
+
|
101 |
if text and recommend_button: # Check if the user entered text and clicked the button
|
102 |
|
103 |
# Embed the query and search for nearest vectors using Faiss
|
|
|
124 |
st.write(e)
|
125 |
|
126 |
with col2:
|
127 |
+
# Выводим информацию о книге на прозрачном фоне
|
128 |
st.markdown(f"""
|
129 |
<div class="transparent-box">
|
130 |
<p><b>Название книги:</b> {books['title'][i]}</p>
|
131 |
<p><b>Автор:</b> {books['author'][i]}</p>
|
132 |
+
<p><b>Описание:</b>{books['annotation'][i]}")
|
133 |
<p><b>Оценка сходства:</b> {similarity_percent:.2f}%</p>
|
134 |
</div>
|
135 |
""", unsafe_allow_html=True)
|
136 |
|
137 |
+
st.write("---")
|