jbdel commited on
Commit
4e0c371
1 Parent(s): c3dd7a0

update api

Browse files
app.py CHANGED
@@ -16,40 +16,38 @@ from zoneinfo import ZoneInfo # Available in Python 3.9 and later
16
  paper_central_df = PaperCentral()
17
 
18
 
19
- def hide_if_logged_in(oauth_token: Optional[gr.OAuthToken]):
20
  if oauth_token is None:
21
- return gr.update(visible=True)
22
- try:
23
- whoami(oauth_token.token)
24
- return gr.update(visible=False)
25
- except requests.exceptions.HTTPError as e:
26
- return gr.update(visible=True)
27
-
28
 
29
- def display_user_info(oauth_token: Optional[gr.OAuthToken]):
30
- if oauth_token is None:
31
- return ""
32
  try:
 
33
  user_info = whoami(oauth_token.token)
 
34
  except requests.exceptions.HTTPError as e:
35
- print(e)
36
- return ""
 
 
 
 
37
  avatar_url = user_info.get("avatarUrl", "")
38
- fullname = user_info.get("fullname", "")
39
  name = user_info.get("name", "")
40
 
41
- # Prepare the custom HTML for the avatar
42
- avatar_html = \
43
- f'''
44
- <div style="display: flex; align-items: center;">
45
- <img alt="Avatar" src="{avatar_url}"
46
- style="border: 2px solid rgb(245, 158, 11); border-radius: 50%; width: 1.38rem; height: 1.38rem; margin-right: 0.5rem;">
47
- <span style="font-size: 1rem;">{name}</span>
48
- </div>
49
- Head to "PR paper-central" tab to modify your paper!
50
- '''
51
 
52
- return gr.update(value=avatar_html, label="User")
 
53
 
54
 
55
  # Create the Gradio Blocks app with custom CSS
@@ -57,8 +55,8 @@ with gr.Blocks(css="style.css") as demo:
57
  gr.Markdown("# Paper Central")
58
  with gr.Row():
59
  with gr.Column(scale=1):
60
- gr.LoginButton(value="PR this space").attach_load_event(hide_if_logged_in, None)
61
- user_info_md = gr.HTML().attach_load_event(display_user_info, None)
62
  with gr.Column(scale=1):
63
  with gr.Accordion(label="⭐Release notes", open=False):
64
  gr.Markdown("""
@@ -69,6 +67,11 @@ with gr.Blocks(css="style.css") as demo:
69
  - **October 4, 2024** – Added functionality to filter papers by title.
70
  """)
71
 
 
 
 
 
 
72
  with gr.Tabs() as tabs:
73
  with gr.Tab("Paper-central", id="tab-paper-central"):
74
  # Create a row for navigation buttons and calendar
@@ -376,12 +379,14 @@ with gr.Blocks(css="style.css") as demo:
376
  fn=update_data,
377
  inputs=inputs,
378
  outputs=paper_central_component,
 
379
  )
380
 
381
  title_search.submit(
382
  fn=update_data,
383
  inputs=inputs,
384
  outputs=paper_central_component,
 
385
  )
386
 
387
  # Set up the event listener for the 'Next Day' button
@@ -389,6 +394,7 @@ with gr.Blocks(css="style.css") as demo:
389
  fn=go_to_next_day,
390
  inputs=inputs,
391
  outputs=[calendar, paper_central_component, date_range_radio],
 
392
  )
393
 
394
  # Set up the event listener for the 'Previous Day' button
@@ -396,6 +402,7 @@ with gr.Blocks(css="style.css") as demo:
396
  fn=go_to_previous_day,
397
  inputs=inputs,
398
  outputs=[calendar, paper_central_component, date_range_radio],
 
399
  )
400
 
401
  # Set up the event listener for the calendar date change
@@ -403,6 +410,7 @@ with gr.Blocks(css="style.css") as demo:
403
  fn=update_data,
404
  inputs=inputs,
405
  outputs=paper_central_component,
 
406
  )
407
 
408
  # Set up the event listener for the Hugging Face options change
@@ -410,6 +418,7 @@ with gr.Blocks(css="style.css") as demo:
410
  fn=update_data,
411
  inputs=inputs,
412
  outputs=paper_central_component,
 
413
  )
414
 
415
  # Event chaining for conference options change
@@ -417,6 +426,7 @@ with gr.Blocks(css="style.css") as demo:
417
  fn=on_conference_options_change,
418
  inputs=inputs,
419
  outputs=[paper_central_component, cat_options, calendar, next_day_btn, prev_day_btn, date_range_radio],
 
420
  )
421
 
422
  # Event chaining for category options change
@@ -424,6 +434,7 @@ with gr.Blocks(css="style.css") as demo:
424
  fn=on_cat_options_change,
425
  inputs=inputs,
426
  outputs=[paper_central_component, conference_options, calendar, next_day_btn, prev_day_btn, date_range_radio],
 
427
  )
428
 
429
  # Set up the event listener for the date range radio button change
@@ -431,6 +442,7 @@ with gr.Blocks(css="style.css") as demo:
431
  fn=update_data,
432
  inputs=inputs,
433
  outputs=paper_central_component,
 
434
  )
435
 
436
  # Load the initial data when the app starts
@@ -473,7 +485,6 @@ with gr.Blocks(css="style.css") as demo:
473
  except ValueError:
474
  conferences = []
475
 
476
- print(conferences)
477
  conferences = gr.update(value=conferences)
478
 
479
  if "hf_options" in request.query_params:
@@ -496,10 +507,16 @@ with gr.Blocks(css="style.css") as demo:
496
  fn=update_data,
497
  inputs=inputs,
498
  outputs=paper_central_component,
499
- api_name=False,
500
  ).then(
501
  fn=echo,
502
- outputs=[calendar, date_range_radio, conference_options, hf_options, tabs]
 
 
 
 
 
 
503
  )
504
 
505
 
 
16
  paper_central_df = PaperCentral()
17
 
18
 
19
+ def logging_flow(oauth_token: Optional[gr.OAuthToken]):
20
  if oauth_token is None:
21
+ # User is not logged in
22
+ visibility_update = gr.update(visible=True)
23
+ user_info_update = gr.update(value="", label="User")
24
+ return visibility_update, user_info_update
 
 
 
25
 
 
 
 
26
  try:
27
+ # Attempt to get user information
28
  user_info = whoami(oauth_token.token)
29
+ visibility_update = gr.update(visible=False)
30
  except requests.exceptions.HTTPError as e:
31
+ # If there's an error (e.g., token is invalid), treat as not logged in
32
+ visibility_update = gr.update(visible=True)
33
+ user_info_update = gr.update(value="", label="User")
34
+ return visibility_update, user_info_update
35
+
36
+ # Prepare user information for display
37
  avatar_url = user_info.get("avatarUrl", "")
 
38
  name = user_info.get("name", "")
39
 
40
+ avatar_html = f'''
41
+ <div style="display: flex; align-items: center;">
42
+ <img alt="Avatar" src="{avatar_url}"
43
+ style="border: 2px solid rgb(245, 158, 11); border-radius: 50%; width: 1.38rem; height: 1.38rem; margin-right: 0.5rem;">
44
+ <span style="font-size: 1rem;">{name}</span>
45
+ </div>
46
+ Head to "PR paper-central" tab to modify your paper!
47
+ '''
 
 
48
 
49
+ user_info_update = gr.update(value=avatar_html, label="User")
50
+ return visibility_update, user_info_update
51
 
52
 
53
  # Create the Gradio Blocks app with custom CSS
 
55
  gr.Markdown("# Paper Central")
56
  with gr.Row():
57
  with gr.Column(scale=1):
58
+ login_button = gr.LoginButton(value="PR this space")
59
+ user_info_md = gr.HTML()
60
  with gr.Column(scale=1):
61
  with gr.Accordion(label="⭐Release notes", open=False):
62
  gr.Markdown("""
 
67
  - **October 4, 2024** – Added functionality to filter papers by title.
68
  """)
69
 
70
+ gr.Button(value="Use paper-central in datasets",
71
+ icon="https://huggingface.co/front/assets/huggingface_logo-noborder.svg",
72
+ size="sm",
73
+ link="https://huggingface.co/datasets/huggingface/paper-central-data")
74
+
75
  with gr.Tabs() as tabs:
76
  with gr.Tab("Paper-central", id="tab-paper-central"):
77
  # Create a row for navigation buttons and calendar
 
379
  fn=update_data,
380
  inputs=inputs,
381
  outputs=paper_central_component,
382
+ api_name=False
383
  )
384
 
385
  title_search.submit(
386
  fn=update_data,
387
  inputs=inputs,
388
  outputs=paper_central_component,
389
+ api_name=False
390
  )
391
 
392
  # Set up the event listener for the 'Next Day' button
 
394
  fn=go_to_next_day,
395
  inputs=inputs,
396
  outputs=[calendar, paper_central_component, date_range_radio],
397
+ api_name=False
398
  )
399
 
400
  # Set up the event listener for the 'Previous Day' button
 
402
  fn=go_to_previous_day,
403
  inputs=inputs,
404
  outputs=[calendar, paper_central_component, date_range_radio],
405
+ api_name=False
406
  )
407
 
408
  # Set up the event listener for the calendar date change
 
410
  fn=update_data,
411
  inputs=inputs,
412
  outputs=paper_central_component,
413
+ api_name=False
414
  )
415
 
416
  # Set up the event listener for the Hugging Face options change
 
418
  fn=update_data,
419
  inputs=inputs,
420
  outputs=paper_central_component,
421
+ api_name=False
422
  )
423
 
424
  # Event chaining for conference options change
 
426
  fn=on_conference_options_change,
427
  inputs=inputs,
428
  outputs=[paper_central_component, cat_options, calendar, next_day_btn, prev_day_btn, date_range_radio],
429
+ api_name=False
430
  )
431
 
432
  # Event chaining for category options change
 
434
  fn=on_cat_options_change,
435
  inputs=inputs,
436
  outputs=[paper_central_component, conference_options, calendar, next_day_btn, prev_day_btn, date_range_radio],
437
+ api_name=False
438
  )
439
 
440
  # Set up the event listener for the date range radio button change
 
442
  fn=update_data,
443
  inputs=inputs,
444
  outputs=paper_central_component,
445
+ api_name=False
446
  )
447
 
448
  # Load the initial data when the app starts
 
485
  except ValueError:
486
  conferences = []
487
 
 
488
  conferences = gr.update(value=conferences)
489
 
490
  if "hf_options" in request.query_params:
 
507
  fn=update_data,
508
  inputs=inputs,
509
  outputs=paper_central_component,
510
+ api_name="update_data",
511
  ).then(
512
  fn=echo,
513
+ outputs=[calendar, date_range_radio, conference_options, hf_options, tabs],
514
+ api_name=False,
515
+ ).then(
516
+ # New then to handle LoginButton and HTML components
517
+ fn=logging_flow,
518
+ outputs=[login_button, user_info_md],
519
+ api_name=False,
520
  )
521
 
522
 
author_leaderboard_contrib_tab.py CHANGED
@@ -46,10 +46,12 @@ def author_resource_leaderboard_tab():
46
  author_search_input.change(
47
  update_leaderboard,
48
  inputs=inputs,
49
- outputs=outputs
 
50
  )
51
  entity_type_filter.change(
52
  update_leaderboard,
53
  inputs=inputs,
54
- outputs=outputs
 
55
  )
 
46
  author_search_input.change(
47
  update_leaderboard,
48
  inputs=inputs,
49
+ outputs=outputs,
50
+ api_name=False,
51
  )
52
  entity_type_filter.change(
53
  update_leaderboard,
54
  inputs=inputs,
55
+ outputs=outputs,
56
+ api_name=False,
57
  )
author_leaderboard_tab.py CHANGED
@@ -32,5 +32,6 @@ def author_leaderboard_tab():
32
  author_search_input.change(
33
  leaderboard.filter,
34
  inputs=[author_search_input],
35
- outputs=[leaderboard_component]
 
36
  )
 
32
  author_search_input.change(
33
  leaderboard.filter,
34
  inputs=[author_search_input],
35
+ outputs=[leaderboard_component],
36
+ api_name=False,
37
  )
df/PaperCentral.py CHANGED
@@ -157,6 +157,20 @@ class PaperCentral:
157
  'conference_name', 'title', 'paper_page', 'authors', 'github_stars']
158
  ]
159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  return paper_central_df
161
 
162
  @staticmethod
 
157
  'conference_name', 'title', 'paper_page', 'authors', 'github_stars']
158
  ]
159
 
160
+ # If arxiv published_date is weekend, switch to Monday
161
+ def adjust_date(dt):
162
+ if dt.weekday() == 5: # Saturday
163
+ return dt + pd.Timedelta(days=2)
164
+ elif dt.weekday() == 6: # Sunday
165
+ return dt + pd.Timedelta(days=1)
166
+ else:
167
+ return dt
168
+
169
+ # Convert 'date' column to datetime
170
+ paper_central_df['date'] = pd.to_datetime(paper_central_df['date'], format='%Y-%m-%d')
171
+ paper_central_df['date'] = paper_central_df['date'].apply(adjust_date)
172
+ paper_central_df['date'] = paper_central_df['date'].dt.strftime('%Y-%m-%d')
173
+
174
  return paper_central_df
175
 
176
  @staticmethod
pr_paper_central_tab.py CHANGED
@@ -10,7 +10,7 @@ import requests
10
  # PR function remains the same
11
  def create_pr_in_hf_dataset(new_entry, oauth_token: gr.OAuthToken):
12
  # Dataset and filename
13
- REPO_ID = 'IAMJB/paper-central-pr-test'
14
  FILENAME = 'data.json'
15
 
16
  # Initialize HfApi
@@ -178,7 +178,8 @@ def pr_paper_central_tab(paper_central_df):
178
  inputs=[arxiv_id_input],
179
  outputs=[message] + [input_fields[field['name']] for field in fields] + [create_pr_button,
180
  create_paper_page_button,
181
- pr_message]
 
182
  )
183
 
184
  # Function to create PR
@@ -201,15 +202,18 @@ def pr_paper_central_tab(paper_central_df):
201
  create_pr_button.click(
202
  fn=lambda: gr.update(visible=True), # Show loading message
203
  inputs=[],
204
- outputs=[loading_message]
 
205
  ).then(
206
  fn=create_pr,
207
  inputs=[arxiv_id_input] + [input_fields[field['name']] for field in fields],
208
- outputs=[pr_message]
 
209
  ).then(
210
  fn=lambda: gr.update(visible=False), # Hide loading message
211
  inputs=[],
212
- outputs=[loading_message]
 
213
  )
214
 
215
  # Function to create paper page
@@ -252,5 +256,6 @@ def pr_paper_central_tab(paper_central_df):
252
  create_paper_page_button.click(
253
  fn=create_paper_page,
254
  inputs=[arxiv_id_input],
255
- outputs=[message]
 
256
  )
 
10
  # PR function remains the same
11
  def create_pr_in_hf_dataset(new_entry, oauth_token: gr.OAuthToken):
12
  # Dataset and filename
13
+ REPO_ID = 'IAMJB/paper-central-pr'
14
  FILENAME = 'data.json'
15
 
16
  # Initialize HfApi
 
178
  inputs=[arxiv_id_input],
179
  outputs=[message] + [input_fields[field['name']] for field in fields] + [create_pr_button,
180
  create_paper_page_button,
181
+ pr_message],
182
+ api_name=False
183
  )
184
 
185
  # Function to create PR
 
202
  create_pr_button.click(
203
  fn=lambda: gr.update(visible=True), # Show loading message
204
  inputs=[],
205
+ outputs=[loading_message],
206
+ api_name=False
207
  ).then(
208
  fn=create_pr,
209
  inputs=[arxiv_id_input] + [input_fields[field['name']] for field in fields],
210
+ outputs=[pr_message],
211
+ api_name=False
212
  ).then(
213
  fn=lambda: gr.update(visible=False), # Hide loading message
214
  inputs=[],
215
+ outputs=[loading_message],
216
+ api_name=False
217
  )
218
 
219
  # Function to create paper page
 
256
  create_paper_page_button.click(
257
  fn=create_paper_page,
258
  inputs=[arxiv_id_input],
259
+ outputs=[message],
260
+ api_name=False
261
  )