zhiminy commited on
Commit
4b2e76d
·
1 Parent(s): 4392559

add Continuous Polling

Browse files
Files changed (1) hide show
  1. app.py +61 -7
app.py CHANGED
@@ -40,7 +40,9 @@ HINT_STRING = "Once signed in, your votes will be recorded securely."
40
  model_metadata = pd.read_json("model_metadata.jsonl", lines=True)
41
 
42
  # Create a dictionary mapping model names to their context lengths
43
- model_context_window = model_metadata.set_index("model_name")["context_window"].to_dict()
 
 
44
 
45
  # Create a dictionary mapping model names to their links
46
  model_links = model_metadata.set_index("model_name")["link"].to_dict()
@@ -587,10 +589,7 @@ def get_leaderboard_data(vote_entry=None, use_cache=True):
587
  ["Rank"] + [col for col in leaderboard_data.columns if col != "Rank"]
588
  ]
589
 
590
- # Make model names clickable with their corresponding links
591
- leaderboard_data["Model"] = leaderboard_data["Model"].apply(
592
- lambda model_name: f'<a href="{model_links[model_name]}" target="_blank">{model_name}</a>'
593
- )
594
 
595
  # Save leaderboard data if this is a new vote
596
  if vote_entry is not None:
@@ -622,8 +621,52 @@ def toggle_submit_button(text):
622
  return gr.update(interactive=True) # Enable the button
623
 
624
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
625
  # Gradio Interface
626
- with gr.Blocks() as app:
627
  user_authenticated = gr.State(False)
628
  models_state = gr.State({})
629
  conversation_state = gr.State({})
@@ -658,7 +701,18 @@ with gr.Blocks() as app:
658
  "Newman Modularity Score",
659
  "PageRank Score",
660
  ],
661
- datatype=["number", "html", "number", "number", "number", "number", "number", "number", "number", "number"],
 
 
 
 
 
 
 
 
 
 
 
662
  )
663
  # Add a citation block in Markdown
664
  citation_component = gr.Markdown(
 
40
  model_metadata = pd.read_json("model_metadata.jsonl", lines=True)
41
 
42
  # Create a dictionary mapping model names to their context lengths
43
+ model_context_window = model_metadata.set_index("model_name")[
44
+ "context_window"
45
+ ].to_dict()
46
 
47
  # Create a dictionary mapping model names to their links
48
  model_links = model_metadata.set_index("model_name")["link"].to_dict()
 
589
  ["Rank"] + [col for col in leaderboard_data.columns if col != "Rank"]
590
  ]
591
 
592
+ # Note: Links are made clickable via JavaScript, keeping plain model names here
 
 
 
593
 
594
  # Save leaderboard data if this is a new vote
595
  if vote_entry is not None:
 
621
  return gr.update(interactive=True) # Enable the button
622
 
623
 
624
+ # JavaScript to make model name links clickable in the leaderboard
625
+ # Uses event delegation on the table container for better stability
626
+ clickable_links_js = (
627
+ """
628
+ function() {
629
+ const modelLinks = """
630
+ + json.dumps(model_links)
631
+ + """;
632
+
633
+ function makeLinksClickable() {
634
+ // Find all table cells in the Model column (2nd column)
635
+ const rows = document.querySelectorAll('table tbody tr');
636
+ rows.forEach(row => {
637
+ const cells = row.querySelectorAll('td');
638
+ if (cells.length >= 2) {
639
+ const modelCell = cells[1]; // Model is the 2nd column
640
+ const cellText = modelCell.textContent.trim();
641
+
642
+ // Check if this cell contains a model name and hasn't been converted yet
643
+ if (modelLinks[cellText] && !modelCell.querySelector('a')) {
644
+ // Create clickable link
645
+ const link = document.createElement('a');
646
+ link.href = modelLinks[cellText];
647
+ link.textContent = cellText;
648
+ link.target = '_blank';
649
+ link.style.color = '#2563eb';
650
+ link.style.textDecoration = 'underline';
651
+ link.style.fontWeight = '500';
652
+
653
+ // Replace text with link
654
+ modelCell.innerHTML = '';
655
+ modelCell.appendChild(link);
656
+ }
657
+ }
658
+ });
659
+ }
660
+
661
+ // Continuous polling approach - runs every 300ms
662
+ // This is the ONLY reliable way with virtual scrolling components
663
+ setInterval(makeLinksClickable, 300);
664
+ }
665
+ """
666
+ )
667
+
668
  # Gradio Interface
669
+ with gr.Blocks(js=clickable_links_js) as app:
670
  user_authenticated = gr.State(False)
671
  models_state = gr.State({})
672
  conversation_state = gr.State({})
 
701
  "Newman Modularity Score",
702
  "PageRank Score",
703
  ],
704
+ datatype=[
705
+ "number",
706
+ "str",
707
+ "number",
708
+ "number",
709
+ "number",
710
+ "number",
711
+ "number",
712
+ "number",
713
+ "number",
714
+ "number",
715
+ ],
716
  )
717
  # Add a citation block in Markdown
718
  citation_component = gr.Markdown(