bradley6597
commited on
Shutter Stock & Date Created Fix
Browse files
app.py
CHANGED
@@ -85,6 +85,8 @@ def same_auth(username, password):
|
|
85 |
|
86 |
|
87 |
|
|
|
|
|
88 |
def search_index(search_text, sd, ks, sort_by, max_results, user_num, search_title, increase = None):
|
89 |
max_results_list = ['10', '25', '50', '75', '100', '250', '500', '1000', '5000', '10000', 'All']
|
90 |
if increase:
|
@@ -108,7 +110,7 @@ def search_index(search_text, sd, ks, sort_by, max_results, user_num, search_tit
|
|
108 |
.first()
|
109 |
.reset_index()
|
110 |
.drop_duplicates())
|
111 |
-
|
112 |
output_df['url'] = output_df['url'].str.replace("/u/0/", f"/u/{int(user_num)}/", regex = False)
|
113 |
if len(sd) == 1:
|
114 |
output_df = output_df[(output_df['filepath'].str.contains(str(sd[0]), regex = False))]
|
@@ -124,7 +126,11 @@ def search_index(search_text, sd, ks, sort_by, max_results, user_num, search_tit
|
|
124 |
output_df2 = output_df2[(output_df2['post_filepath'].str.contains(keystage_filter, regex = True))]
|
125 |
if output_df2.shape[0] == 0:
|
126 |
output_df2 = output_df[(output_df['post_filepath'].str.contains(keystage_filter, regex = True))]
|
127 |
-
|
|
|
|
|
|
|
|
|
128 |
output_df2['ind'] = output_df2.index
|
129 |
if sort_by == 'Relevance':
|
130 |
output_df2 = output_df2.sort_values(by = ['missing_desc', 'ind'], ascending = [True, True])
|
@@ -134,8 +140,7 @@ def search_index(search_text, sd, ks, sort_by, max_results, user_num, search_tit
|
|
134 |
output_df2 = output_df2.sort_values(by = ['title'], ascending = True)
|
135 |
|
136 |
total_returned = 'No. of Results to Return (Total: ' + str(output_df2.shape[0]) + ')'
|
137 |
-
|
138 |
-
|
139 |
if max_results != 'All':
|
140 |
if output_df2.shape[0] > int(max_results):
|
141 |
load_more_visible = True
|
@@ -247,7 +252,7 @@ with gr.Blocks(css=style) as app:
|
|
247 |
search_prompt = gr.Textbox(placeholder = 'search for an illustration', label = 'Search', elem_id = 'search_term')
|
248 |
title_search = gr.Checkbox(label = 'Search title only')
|
249 |
# with gr.Row():
|
250 |
-
shared_drive = gr.Dropdown(choices = ['Illustrations - 01-10 to 07-22', 'Illustrations - Now'], multiselect = True, label = 'Shared Drive', value = ['Illustrations - 01-10 to 07-22', 'Illustrations - Now'])
|
251 |
key_stage = gr.Dropdown(choices = ['EYFS', 'KS1', 'KS2'], multiselect = True, label = 'Key Stage', value = ['EYFS', 'KS1', 'KS2'])
|
252 |
sort_by = gr.Dropdown(choices = ['Relevance', 'Date Created', 'A-Z'], value = 'Relevance', multiselect = False, label = 'Sort By')
|
253 |
max_return = gr.Dropdown(choices = ['10', '25', '50', '75', '100', '250', '500', '1000', '5000', '10000', 'All'], value = '50', multiselect = False, label = 'No. of Results to Return (Total: 0)')
|
|
|
85 |
|
86 |
|
87 |
|
88 |
+
|
89 |
+
|
90 |
def search_index(search_text, sd, ks, sort_by, max_results, user_num, search_title, increase = None):
|
91 |
max_results_list = ['10', '25', '50', '75', '100', '250', '500', '1000', '5000', '10000', 'All']
|
92 |
if increase:
|
|
|
110 |
.first()
|
111 |
.reset_index()
|
112 |
.drop_duplicates())
|
113 |
+
output_df['Date Created'] = pd.to_datetime(output_df['Date Created'], format = 'mixed')
|
114 |
output_df['url'] = output_df['url'].str.replace("/u/0/", f"/u/{int(user_num)}/", regex = False)
|
115 |
if len(sd) == 1:
|
116 |
output_df = output_df[(output_df['filepath'].str.contains(str(sd[0]), regex = False))]
|
|
|
126 |
output_df2 = output_df2[(output_df2['post_filepath'].str.contains(keystage_filter, regex = True))]
|
127 |
if output_df2.shape[0] == 0:
|
128 |
output_df2 = output_df[(output_df['post_filepath'].str.contains(keystage_filter, regex = True))]
|
129 |
+
else:
|
130 |
+
output_df['abstract'] = output_df['abstract'].str.lower()
|
131 |
+
output_df['post_filepath'] = output_df['post_filepath'].str.lower()
|
132 |
+
output_df['missing_desc'] = np.where(output_df['abstract'].str.contains('eyfs|ks1|ks2', regex = True), 0, 1)
|
133 |
+
output_df2 = output_df
|
134 |
output_df2['ind'] = output_df2.index
|
135 |
if sort_by == 'Relevance':
|
136 |
output_df2 = output_df2.sort_values(by = ['missing_desc', 'ind'], ascending = [True, True])
|
|
|
140 |
output_df2 = output_df2.sort_values(by = ['title'], ascending = True)
|
141 |
|
142 |
total_returned = 'No. of Results to Return (Total: ' + str(output_df2.shape[0]) + ')'
|
143 |
+
|
|
|
144 |
if max_results != 'All':
|
145 |
if output_df2.shape[0] > int(max_results):
|
146 |
load_more_visible = True
|
|
|
252 |
search_prompt = gr.Textbox(placeholder = 'search for an illustration', label = 'Search', elem_id = 'search_term')
|
253 |
title_search = gr.Checkbox(label = 'Search title only')
|
254 |
# with gr.Row():
|
255 |
+
shared_drive = gr.Dropdown(choices = ['Illustrations - 01-10 to 07-22', 'Illustrations - Now', 'Shutter Stock Images'], multiselect = True, label = 'Shared Drive', value = ['Illustrations - 01-10 to 07-22', 'Illustrations - Now'])
|
256 |
key_stage = gr.Dropdown(choices = ['EYFS', 'KS1', 'KS2'], multiselect = True, label = 'Key Stage', value = ['EYFS', 'KS1', 'KS2'])
|
257 |
sort_by = gr.Dropdown(choices = ['Relevance', 'Date Created', 'A-Z'], value = 'Relevance', multiselect = False, label = 'Sort By')
|
258 |
max_return = gr.Dropdown(choices = ['10', '25', '50', '75', '100', '250', '500', '1000', '5000', '10000', 'All'], value = '50', multiselect = False, label = 'No. of Results to Return (Total: 0)')
|