Spaces:
Build error
Build error
оптимизация apply_sort функции
Browse files- ui_components.py +1 -8
- utils.py +3 -1
ui_components.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from datetime import datetime
|
| 3 |
|
| 4 |
@st.cache_resource
|
| 5 |
def load_css():
|
|
@@ -21,10 +20,6 @@ def render_sidebar(cookie, locale, all_langs, moods, all_tags):
|
|
| 21 |
if st.session_state.lang_select != st.session_state.lang:
|
| 22 |
cookie.set("lang", st.session_state.lang_select, secure=True, same_site=None)
|
| 23 |
|
| 24 |
-
def on_sort_change():
|
| 25 |
-
if st.session_state.sort_select == locale['filter_sort'][4]:
|
| 26 |
-
st.session_state.user_random = int(datetime.now().timestamp())
|
| 27 |
-
|
| 28 |
st.selectbox(
|
| 29 |
locale['filter_lang'],
|
| 30 |
all_langs,
|
|
@@ -39,9 +34,7 @@ def render_sidebar(cookie, locale, all_langs, moods, all_tags):
|
|
| 39 |
search_query = st.text_input(locale['filter_search'], "")
|
| 40 |
sort_option = st.selectbox(
|
| 41 |
locale['filter_sort_title'],
|
| 42 |
-
locale['filter_sort']
|
| 43 |
-
on_change=on_sort_change,
|
| 44 |
-
key="sort_select"
|
| 45 |
)
|
| 46 |
absurdity_range = st.slider(locale['filter_absurd'], 0, 10, (0, 10))
|
| 47 |
selected_mood = st.selectbox(locale['filter_mood'], moods)
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
|
| 3 |
@st.cache_resource
|
| 4 |
def load_css():
|
|
|
|
| 20 |
if st.session_state.lang_select != st.session_state.lang:
|
| 21 |
cookie.set("lang", st.session_state.lang_select, secure=True, same_site=None)
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
st.selectbox(
|
| 24 |
locale['filter_lang'],
|
| 25 |
all_langs,
|
|
|
|
| 34 |
search_query = st.text_input(locale['filter_search'], "")
|
| 35 |
sort_option = st.selectbox(
|
| 36 |
locale['filter_sort_title'],
|
| 37 |
+
locale['filter_sort']
|
|
|
|
|
|
|
| 38 |
)
|
| 39 |
absurdity_range = st.slider(locale['filter_absurd'], 0, 10, (0, 10))
|
| 40 |
selected_mood = st.selectbox(locale['filter_mood'], moods)
|
utils.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
|
| 3 |
@st.cache_data
|
| 4 |
def get_search_mask(df, search_query):
|
|
@@ -31,6 +32,7 @@ def apply_filters(locale, df, search_query, absurdity_range, selected_mood, sele
|
|
| 31 |
|
| 32 |
return filtered_df
|
| 33 |
|
|
|
|
| 34 |
def apply_sort(locale, df, sort_option):
|
| 35 |
# Сортировка
|
| 36 |
sort_columns = {
|
|
@@ -43,6 +45,6 @@ def apply_sort(locale, df, sort_option):
|
|
| 43 |
col, asc = sort_columns[sort_option]
|
| 44 |
|
| 45 |
if col == "random":
|
| 46 |
-
return df.sample(frac=1, random_state=
|
| 47 |
else:
|
| 48 |
return df.sort_values(col, ascending=asc)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from datetime import datetime
|
| 3 |
|
| 4 |
@st.cache_data
|
| 5 |
def get_search_mask(df, search_query):
|
|
|
|
| 32 |
|
| 33 |
return filtered_df
|
| 34 |
|
| 35 |
+
@st.cache_data(ttl=120)
|
| 36 |
def apply_sort(locale, df, sort_option):
|
| 37 |
# Сортировка
|
| 38 |
sort_columns = {
|
|
|
|
| 45 |
col, asc = sort_columns[sort_option]
|
| 46 |
|
| 47 |
if col == "random":
|
| 48 |
+
return df.sample(frac=1, random_state=int(datetime.now().timestamp()))
|
| 49 |
else:
|
| 50 |
return df.sort_values(col, ascending=asc)
|