akhaliq HF staff commited on
Commit
a767c65
·
verified ·
1 Parent(s): 03f9262

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -17
app.py CHANGED
@@ -365,8 +365,11 @@ def change_sort_method_ui(method: str) -> str:
365
  Changes the sort method based on user selection.
366
  """
367
  logger.info(f"Changing sort method to: {method}")
368
- paper_manager.set_sort_method(method.lower())
369
- return paper_manager.get_current_page_papers()
 
 
 
370
 
371
 
372
  # --- CSS Styling ---
@@ -545,6 +548,7 @@ with demo:
545
 
546
  Once your paper is submitted, it will automatically appear in this demo.
547
  """)
 
548
  # Hacker News-like Header with "Hot" and "New" sort options
549
  with gr.Row():
550
  # Left side: Site title
@@ -557,44 +561,54 @@ with demo:
557
  </span>
558
  </td>
559
  <td align="right" class="sort-buttons">
560
- <button onclick="gradioApp().getElementById('hot_sort').click()">Hot</button> |
561
- <button onclick="gradioApp().getElementById('new_sort').click()">New</button>
562
  </td>
563
  </tr>
564
  </table>
565
  """, show_label=False)
566
- # Hidden buttons to trigger sort methods
567
- hot_sort = gr.Button("Hot Sort", visible=False, elem_id="hot_sort")
568
- new_sort = gr.Button("New Sort", visible=False, elem_id="new_sort")
 
 
569
  # Paper list
570
  paper_list = gr.HTML()
 
571
  # Navigation Buttons
572
  with gr.Row():
573
  prev_button = gr.Button("Prev")
574
  next_button = gr.Button("Next")
575
-
576
  # Load papers on app start
577
  demo.load(
578
  fn=lambda: paper_manager.get_current_page_papers(),
579
  outputs=[paper_list]
580
  )
581
-
582
  # Button clicks for pagination
583
- prev_button.click(paper_manager.prev_page, outputs=[paper_list])
584
- next_button.click(paper_manager.next_page, outputs=[paper_list])
585
-
586
- # Hidden buttons trigger sort methods
587
- hot_sort.click(
 
 
 
 
 
 
 
 
588
  fn=lambda: change_sort_method_ui("hot"),
589
  inputs=[],
590
  outputs=[paper_list]
591
  )
592
- new_sort.click(
593
  fn=lambda: change_sort_method_ui("new"),
594
  inputs=[],
595
  outputs=[paper_list]
596
  )
597
-
598
  # Footer - Removed as per request
599
  # Removed the footer markdown section
600
 
@@ -602,4 +616,4 @@ with demo:
602
  # --- Launch the App ---
603
 
604
  if __name__ == "__main__":
605
- demo.launch()
 
365
  Changes the sort method based on user selection.
366
  """
367
  logger.info(f"Changing sort method to: {method}")
368
+ success = paper_manager.set_sort_method(method.lower())
369
+ if success:
370
+ return paper_manager.get_current_page_papers()
371
+ else:
372
+ return "<div class='no-papers'>Failed to change sort method.</div>"
373
 
374
 
375
  # --- CSS Styling ---
 
548
 
549
  Once your paper is submitted, it will automatically appear in this demo.
550
  """)
551
+
552
  # Hacker News-like Header with "Hot" and "New" sort options
553
  with gr.Row():
554
  # Left side: Site title
 
561
  </span>
562
  </td>
563
  <td align="right" class="sort-buttons">
564
+ <!-- Removed custom HTML buttons -->
 
565
  </td>
566
  </tr>
567
  </table>
568
  """, show_label=False)
569
+ # Right side: Gradio Buttons for "Hot" and "New"
570
+ with gr.Column(elem_classes=["sort-buttons"]):
571
+ hot_button = gr.Button("Hot", elem_id="hot_button")
572
+ new_button = gr.Button("New", elem_id="new_button")
573
+
574
  # Paper list
575
  paper_list = gr.HTML()
576
+
577
  # Navigation Buttons
578
  with gr.Row():
579
  prev_button = gr.Button("Prev")
580
  next_button = gr.Button("Next")
581
+
582
  # Load papers on app start
583
  demo.load(
584
  fn=lambda: paper_manager.get_current_page_papers(),
585
  outputs=[paper_list]
586
  )
587
+
588
  # Button clicks for pagination
589
+ prev_button.click(
590
+ fn=lambda: paper_manager.prev_page(),
591
+ inputs=[],
592
+ outputs=[paper_list]
593
+ )
594
+ next_button.click(
595
+ fn=lambda: paper_manager.next_page(),
596
+ inputs=[],
597
+ outputs=[paper_list]
598
+ )
599
+
600
+ # Gradio Buttons trigger sort methods directly
601
+ hot_button.click(
602
  fn=lambda: change_sort_method_ui("hot"),
603
  inputs=[],
604
  outputs=[paper_list]
605
  )
606
+ new_button.click(
607
  fn=lambda: change_sort_method_ui("new"),
608
  inputs=[],
609
  outputs=[paper_list]
610
  )
611
+
612
  # Footer - Removed as per request
613
  # Removed the footer markdown section
614
 
 
616
  # --- Launch the App ---
617
 
618
  if __name__ == "__main__":
619
+ demo.launch()