m7n commited on
Commit
c985084
·
verified ·
1 Parent(s): d68fabe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -5
app.py CHANGED
@@ -90,18 +90,35 @@ def query_records(search_term):
90
  except:
91
  return ' '
92
 
93
- # Fetch records based on the search term
94
- query = Works().search_filter(abstract=search_term)
95
-
 
96
  records = []
97
- for record in chain(*query.paginate(per_page=200)):
 
 
98
  records.append(record)
 
 
 
 
 
 
 
99
 
 
100
  records_df = pd.DataFrame(records)
101
  records_df['abstract'] = [invert_abstract(t) for t in records_df['abstract_inverted_index']]
 
102
  records_df['parsed_publication'] = [get_pub(x) for x in records_df['primary_location']]
103
 
104
 
 
 
 
 
 
105
  return records_df
106
 
107
 
@@ -170,7 +187,7 @@ def create_embeddings(texts_to_embedd):
170
 
171
  def predict(text_input, sample_size_slider, reduce_sample_checkbox, progress=gr.Progress()):
172
 
173
- progress(0.1, desc="Getting queried data...")
174
  # get data.
175
  records_df = query_records(text_input)
176
  if reduce_sample_checkbox:
 
90
  except:
91
  return ' '
92
 
93
+ # Fetch records based on the search term in the abstract!
94
+ query = Works().search([search_term])
95
+ query_length = Works().search([search_term]).count()
96
+
97
  records = []
98
+ total_pages = (query_length + 199) // 200 # Calculate total number of pages
99
+
100
+ for i, record in enumerate(chain(*query.paginate(per_page=200))):
101
  records.append(record)
102
+
103
+ # Calculate progress from 0 to 0.1
104
+ progress = min(0.1, (i + 1) / query_length * 0.1)
105
+
106
+ # Update progress bar
107
+ progress(progress, desc="Getting queried data...")
108
+
109
 
110
+
111
  records_df = pd.DataFrame(records)
112
  records_df['abstract'] = [invert_abstract(t) for t in records_df['abstract_inverted_index']]
113
+
114
  records_df['parsed_publication'] = [get_pub(x) for x in records_df['primary_location']]
115
 
116
 
117
+ records_df['parsed_publication'] = records_df['parsed_publication'].fillna(' ')
118
+ records_df['abstract'] = records_df['abstract'].fillna(' ')
119
+ records_df['title'] = records_df['title'].fillna(' ')
120
+
121
+
122
  return records_df
123
 
124
 
 
187
 
188
  def predict(text_input, sample_size_slider, reduce_sample_checkbox, progress=gr.Progress()):
189
 
190
+
191
  # get data.
192
  records_df = query_records(text_input)
193
  if reduce_sample_checkbox: