jbdel commited on
Commit
1a22124
1 Parent(s): d0950b7

add title search

Browse files
Files changed (3) hide show
  1. app.py +56 -5
  2. constants.py +1 -1
  3. df/PaperCentral.py +17 -0
app.py CHANGED
@@ -11,6 +11,11 @@ paper_central_df = PaperCentral()
11
  with gr.Blocks(css="style.css") as demo:
12
  gr.Markdown("# Paper Central")
13
 
 
 
 
 
 
14
  # Create a row for navigation buttons and calendar
15
  with gr.Row():
16
  with gr.Column(scale=1):
@@ -69,12 +74,17 @@ with gr.Blocks(css="style.css") as demo:
69
  label="Conference options",
70
  choices=["In proceedings"] + PaperCentral.CONFERENCES
71
  )
 
 
 
 
 
 
 
 
 
 
72
 
73
- # Define a Textbox for author search
74
- author_search = gr.Textbox(
75
- label="Search Authors",
76
- placeholder="Enter author name",
77
- )
78
  # Define the Dataframe component to display paper data
79
  # List of columns in your DataFrame
80
  columns = paper_central_df.COLUMNS_START_PAPER_PAGE
@@ -90,6 +100,7 @@ with gr.Blocks(css="style.css") as demo:
90
  interactive=False,
91
  height=1000,
92
  elem_id="table",
 
93
  )
94
 
95
 
@@ -100,6 +111,7 @@ with gr.Blocks(css="style.css") as demo:
100
  hf_options_list: List[str],
101
  conference_options_list: List[str],
102
  author_search_input: str,
 
103
  ) -> tuple:
104
  """
105
  Moves the selected date to the next day and updates the data.
@@ -130,6 +142,7 @@ with gr.Blocks(css="style.css") as demo:
130
  hf_options=hf_options_list,
131
  conference_options=conference_options_list,
132
  author_search_input=author_search_input,
 
133
  )
134
 
135
  # Return the new date and updated Dataframe
@@ -143,6 +156,7 @@ with gr.Blocks(css="style.css") as demo:
143
  hf_options_list: List[str],
144
  conference_options_list: List[str],
145
  author_search_input: str,
 
146
  ) -> tuple:
147
  """
148
  Moves the selected date to the previous day and updates the data.
@@ -173,6 +187,7 @@ with gr.Blocks(css="style.css") as demo:
173
  hf_options=hf_options_list,
174
  conference_options=conference_options_list,
175
  author_search_input=author_search_input,
 
176
  )
177
 
178
  # Return the new date and updated Dataframe
@@ -186,6 +201,7 @@ with gr.Blocks(css="style.css") as demo:
186
  hf_options_list: List[str],
187
  conference_options_list: List[str],
188
  author_search_input: str,
 
189
  ):
190
  """
191
  Updates the data displayed in the Dataframe based on the selected date and options.
@@ -205,6 +221,7 @@ with gr.Blocks(css="style.css") as demo:
205
  hf_options=hf_options_list,
206
  conference_options=conference_options_list,
207
  author_search_input=author_search_input,
 
208
  )
209
 
210
 
@@ -215,6 +232,7 @@ with gr.Blocks(css="style.css") as demo:
215
  hf_options_list: List[str],
216
  conference_options_list: List[str],
217
  author_search_input: str,
 
218
  ):
219
 
220
  cat_options_update = gr.update()
@@ -231,6 +249,7 @@ with gr.Blocks(css="style.css") as demo:
231
  hf_options_list,
232
  conference_options_list,
233
  author_search_input,
 
234
  )
235
  visible = False
236
 
@@ -248,6 +267,7 @@ with gr.Blocks(css="style.css") as demo:
248
  hf_options_list: List[str],
249
  conference_options_list: List[str],
250
  author_search_input: str,
 
251
  ):
252
  conference_options_update = gr.update()
253
  paper_central_component_update = gr.update()
@@ -263,6 +283,7 @@ with gr.Blocks(css="style.css") as demo:
263
  hf_options_list,
264
  [],
265
  author_search_input,
 
266
  )
267
  visible = True
268
 
@@ -279,6 +300,7 @@ with gr.Blocks(css="style.css") as demo:
279
  hf_options,
280
  conference_options,
281
  author_search,
 
282
  ]
283
 
284
  # Set up the event listener for the author search
@@ -288,6 +310,12 @@ with gr.Blocks(css="style.css") as demo:
288
  outputs=paper_central_component,
289
  )
290
 
 
 
 
 
 
 
291
  # Set up the event listener for the 'Next Day' button
292
  next_day_btn.click(
293
  fn=go_to_next_day,
@@ -331,11 +359,34 @@ with gr.Blocks(css="style.css") as demo:
331
  )
332
 
333
  # Load the initial data when the app starts
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
334
  demo.load(
335
  fn=update_data,
336
  inputs=inputs,
337
  outputs=paper_central_component,
338
  api_name=False,
 
 
339
  )
340
 
341
 
 
11
  with gr.Blocks(css="style.css") as demo:
12
  gr.Markdown("# Paper Central")
13
 
14
+ with gr.Accordion(label="⭐Release notes", open=False):
15
+ gr.Markdown("""
16
+ 4/10/2024 - You can now filter by Title
17
+ """)
18
+
19
  # Create a row for navigation buttons and calendar
20
  with gr.Row():
21
  with gr.Column(scale=1):
 
74
  label="Conference options",
75
  choices=["In proceedings"] + PaperCentral.CONFERENCES
76
  )
77
+ with gr.Row():
78
+ # Define a Textbox for author search
79
+ author_search = gr.Textbox(
80
+ label="Search Authors",
81
+ placeholder="Enter author name",
82
+ )
83
+ title_search = gr.Textbox(
84
+ label="Search Title",
85
+ placeholder="Enter keywords",
86
+ )
87
 
 
 
 
 
 
88
  # Define the Dataframe component to display paper data
89
  # List of columns in your DataFrame
90
  columns = paper_central_df.COLUMNS_START_PAPER_PAGE
 
100
  interactive=False,
101
  height=1000,
102
  elem_id="table",
103
+ wrap=True,
104
  )
105
 
106
 
 
111
  hf_options_list: List[str],
112
  conference_options_list: List[str],
113
  author_search_input: str,
114
+ title_search_input: str,
115
  ) -> tuple:
116
  """
117
  Moves the selected date to the next day and updates the data.
 
142
  hf_options=hf_options_list,
143
  conference_options=conference_options_list,
144
  author_search_input=author_search_input,
145
+ title_search_input=title_search_input,
146
  )
147
 
148
  # Return the new date and updated Dataframe
 
156
  hf_options_list: List[str],
157
  conference_options_list: List[str],
158
  author_search_input: str,
159
+ title_search_input: str,
160
  ) -> tuple:
161
  """
162
  Moves the selected date to the previous day and updates the data.
 
187
  hf_options=hf_options_list,
188
  conference_options=conference_options_list,
189
  author_search_input=author_search_input,
190
+ title_search_input=title_search_input,
191
  )
192
 
193
  # Return the new date and updated Dataframe
 
201
  hf_options_list: List[str],
202
  conference_options_list: List[str],
203
  author_search_input: str,
204
+ title_search_input: str,
205
  ):
206
  """
207
  Updates the data displayed in the Dataframe based on the selected date and options.
 
221
  hf_options=hf_options_list,
222
  conference_options=conference_options_list,
223
  author_search_input=author_search_input,
224
+ title_search_input=title_search_input,
225
  )
226
 
227
 
 
232
  hf_options_list: List[str],
233
  conference_options_list: List[str],
234
  author_search_input: str,
235
+ title_search_input: str,
236
  ):
237
 
238
  cat_options_update = gr.update()
 
249
  hf_options_list,
250
  conference_options_list,
251
  author_search_input,
252
+ title_search_input,
253
  )
254
  visible = False
255
 
 
267
  hf_options_list: List[str],
268
  conference_options_list: List[str],
269
  author_search_input: str,
270
+ title_search_input: str,
271
  ):
272
  conference_options_update = gr.update()
273
  paper_central_component_update = gr.update()
 
283
  hf_options_list,
284
  [],
285
  author_search_input,
286
+ title_search_input,
287
  )
288
  visible = True
289
 
 
300
  hf_options,
301
  conference_options,
302
  author_search,
303
+ title_search,
304
  ]
305
 
306
  # Set up the event listener for the author search
 
310
  outputs=paper_central_component,
311
  )
312
 
313
+ title_search.submit(
314
+ fn=update_data,
315
+ inputs=inputs,
316
+ outputs=paper_central_component,
317
+ )
318
+
319
  # Set up the event listener for the 'Next Day' button
320
  next_day_btn.click(
321
  fn=go_to_next_day,
 
359
  )
360
 
361
  # Load the initial data when the app starts
362
+ request = gr.Request()
363
+
364
+
365
+ def echo(request: gr.Request):
366
+ """
367
+ Echoes the input text and prints request details.
368
+
369
+ Args:
370
+ text (str): The input text from the user.
371
+ request (gr.Request): The HTTP request object.
372
+
373
+ Returns:
374
+ str: The echoed text.
375
+ """
376
+ if request:
377
+ print("Request headers dictionary:", dict(request.headers))
378
+ print("IP address:", request.client.host)
379
+ print("Query parameters:", dict(request.query_params))
380
+ print("Session hash:", request.session_hash)
381
+
382
+
383
  demo.load(
384
  fn=update_data,
385
  inputs=inputs,
386
  outputs=paper_central_component,
387
  api_name=False,
388
+ ).then(
389
+ fn=echo,
390
  )
391
 
392
 
constants.py CHANGED
@@ -5,4 +5,4 @@ DATASET_DAILY_PAPERS = "hysts-bot-data/daily-papers"
5
  DATASET_DAILY_PAPERS_STATS = "hysts-bot-data/daily-papers-stats"
6
  DATASET_COMMUNITY_SCIENCE = "huggingface/community-science-paper-v2"
7
  # DATASET_PAPER_CENTRAL = "huggingface/paper-central-data"
8
- DATASET_PAPER_CENTRAL = "huggingface/paper-central-data-2"
 
5
  DATASET_DAILY_PAPERS_STATS = "hysts-bot-data/daily-papers-stats"
6
  DATASET_COMMUNITY_SCIENCE = "huggingface/community-science-paper-v2"
7
  # DATASET_PAPER_CENTRAL = "huggingface/paper-central-data"
8
+ DATASET_PAPER_CENTRAL = "huggingface/paper-central-data"
df/PaperCentral.py CHANGED
@@ -276,6 +276,7 @@ class PaperCentral:
276
  hf_options: Optional[List[str]] = None,
277
  conference_options: Optional[List[str]] = None,
278
  author_search_input: Optional[str] = None,
 
279
  ) -> gr.update:
280
  """
281
  Filter the DataFrame based on selected date and options, and prepare it for display.
@@ -293,6 +294,22 @@ class PaperCentral:
293
  # Start with the initial columns to display
294
  columns_to_show: List[str] = PaperCentral.COLUMNS_START_PAPER_PAGE.copy()
295
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
296
  if author_search_input:
297
  if 'authors' not in columns_to_show:
298
  columns_to_show.append('authors')
 
276
  hf_options: Optional[List[str]] = None,
277
  conference_options: Optional[List[str]] = None,
278
  author_search_input: Optional[str] = None,
279
+ title_search_input: Optional[str] = None,
280
  ) -> gr.update:
281
  """
282
  Filter the DataFrame based on selected date and options, and prepare it for display.
 
294
  # Start with the initial columns to display
295
  columns_to_show: List[str] = PaperCentral.COLUMNS_START_PAPER_PAGE.copy()
296
 
297
+ if title_search_input:
298
+ if 'title' not in columns_to_show:
299
+ columns_to_show.append('authors')
300
+
301
+ search_string = title_search_input.lower()
302
+
303
+ def title_match(title):
304
+ if isinstance(title, str):
305
+ # If authors_list is a single string
306
+ return search_string in title.lower()
307
+ else:
308
+ # Handle unexpected data types
309
+ return False
310
+
311
+ filtered_df = filtered_df[filtered_df['title'].apply(title_match)]
312
+
313
  if author_search_input:
314
  if 'authors' not in columns_to_show:
315
  columns_to_show.append('authors')