Spaces:
Runtime error
Runtime error
app search speed 2.0
Browse files- app.py +2 -7
- pages/search.py +13 -8
app.py
CHANGED
|
@@ -2,9 +2,6 @@ import pandas as pd
|
|
| 2 |
import streamlit as st
|
| 3 |
import random
|
| 4 |
|
| 5 |
-
if 'selected_series' not in st.session_state:
|
| 6 |
-
st.session_state.selected_series = None
|
| 7 |
-
|
| 8 |
if 'button_clicked' not in st.session_state:
|
| 9 |
st.session_state.button_clicked = False
|
| 10 |
|
|
@@ -21,10 +18,9 @@ def show_serial(number, score=None):
|
|
| 21 |
st.caption(data.iloc[number, 3])
|
| 22 |
if score:
|
| 23 |
st.write(f'{score[1]} metric: {score[0]:.4f}')
|
| 24 |
-
with col3:
|
| 25 |
st.markdown(f'[Ссылка]({data.iloc[number, 0]})')
|
| 26 |
-
|
| 27 |
-
|
| 28 |
|
| 29 |
|
| 30 |
st.title('Рекомендатор сериалов')
|
|
@@ -51,7 +47,6 @@ with cols[3]:
|
|
| 51 |
|
| 52 |
if st.button('Дай 10 случайных сериалов', use_container_width=True):
|
| 53 |
st.session_state.button_clicked = True
|
| 54 |
-
st.session_state.selected_series = None
|
| 55 |
|
| 56 |
if st.session_state.button_clicked:
|
| 57 |
for _ in range(10):
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
import random
|
| 4 |
|
|
|
|
|
|
|
|
|
|
| 5 |
if 'button_clicked' not in st.session_state:
|
| 6 |
st.session_state.button_clicked = False
|
| 7 |
|
|
|
|
| 18 |
st.caption(data.iloc[number, 3])
|
| 19 |
if score:
|
| 20 |
st.write(f'{score[1]} metric: {score[0]:.4f}')
|
|
|
|
| 21 |
st.markdown(f'[Ссылка]({data.iloc[number, 0]})')
|
| 22 |
+
with col3:
|
| 23 |
+
st.text_area("Описание", value=data.iloc[number, 4], height=300, disabled=True)
|
| 24 |
|
| 25 |
|
| 26 |
st.title('Рекомендатор сериалов')
|
|
|
|
| 47 |
|
| 48 |
if st.button('Дай 10 случайных сериалов', use_container_width=True):
|
| 49 |
st.session_state.button_clicked = True
|
|
|
|
| 50 |
|
| 51 |
if st.session_state.button_clicked:
|
| 52 |
for _ in range(10):
|
pages/search.py
CHANGED
|
@@ -11,6 +11,12 @@ def load_model():
|
|
| 11 |
return SentenceTransformer("paraphrase-multilingual-mpnet-base-v2")
|
| 12 |
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
@st.cache_resource
|
| 15 |
def compute_index(_model, sentences):
|
| 16 |
embeddings = _model.encode(sentences).astype('float32')
|
|
@@ -28,14 +34,7 @@ def compute_index(_model, sentences):
|
|
| 28 |
|
| 29 |
|
| 30 |
model = load_model()
|
| 31 |
-
|
| 32 |
-
sentences = data['description'].tolist()
|
| 33 |
-
|
| 34 |
-
# indices = {
|
| 35 |
-
# 'L2': faiss.read_index("models/index_l2.faiss"),
|
| 36 |
-
# 'Dot': faiss.read_index("models/index_dot.faiss"),
|
| 37 |
-
# 'Cos': faiss.read_index("models/index_cosine.faiss")
|
| 38 |
-
# }
|
| 39 |
|
| 40 |
index_l2, index_dot, index_cosine = compute_index(model, sentences)
|
| 41 |
indices = {
|
|
@@ -44,6 +43,12 @@ indices = {
|
|
| 44 |
'Cos': index_cosine
|
| 45 |
}
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
with st.form(key='submit'):
|
| 48 |
cols = st.columns(2)
|
| 49 |
with cols[0]:
|
|
|
|
| 11 |
return SentenceTransformer("paraphrase-multilingual-mpnet-base-v2")
|
| 12 |
|
| 13 |
|
| 14 |
+
@st.cache_resource
|
| 15 |
+
def get_shows():
|
| 16 |
+
data = pd.read_csv('data/data.csv')
|
| 17 |
+
return data['description'].tolist()
|
| 18 |
+
|
| 19 |
+
|
| 20 |
@st.cache_resource
|
| 21 |
def compute_index(_model, sentences):
|
| 22 |
embeddings = _model.encode(sentences).astype('float32')
|
|
|
|
| 34 |
|
| 35 |
|
| 36 |
model = load_model()
|
| 37 |
+
sentences = get_shows()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
index_l2, index_dot, index_cosine = compute_index(model, sentences)
|
| 40 |
indices = {
|
|
|
|
| 43 |
'Cos': index_cosine
|
| 44 |
}
|
| 45 |
|
| 46 |
+
# indices = {
|
| 47 |
+
# 'L2': faiss.read_index("models/index_l2.faiss"),
|
| 48 |
+
# 'Dot': faiss.read_index("models/index_dot.faiss"),
|
| 49 |
+
# 'Cos': faiss.read_index("models/index_cosine.faiss")
|
| 50 |
+
# }
|
| 51 |
+
|
| 52 |
with st.form(key='submit'):
|
| 53 |
cols = st.columns(2)
|
| 54 |
with cols[0]:
|