Spaces:
Running
Running
Jae-Won Chung
commited on
Commit
•
946a6c9
1
Parent(s):
a1a3701
Shuffle model order
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
from __future__ import annotations
|
2 |
|
|
|
3 |
import json
|
4 |
import random
|
5 |
import yaml
|
@@ -365,11 +366,10 @@ controller_addr = os.environ["COLOSSEUM_CONTROLLER_ADDR"]
|
|
365 |
global_controller_client = ControllerClient(controller_addr=controller_addr, timeout=15)
|
366 |
|
367 |
# Load the list of models. To reload, the app should be restarted.
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
user_pref_to_model_name = dict(zip(model_preference_dropdown_choices, ["Random"] + available_models))
|
373 |
|
374 |
# Colosseum helper functions.
|
375 |
def enable_interact():
|
@@ -401,6 +401,14 @@ def consumed_more_energy_message(energy_a, energy_b):
|
|
401 |
return f"<h2>That response <span class='red-text'>consumed {how_much} more energy</span> ({energy_a:,.0f} J vs. {energy_b:,.0f} J).</h2>"
|
402 |
|
403 |
# Colosseum event handlers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
404 |
def add_prompt_disable_submit(prompt, history_a, history_b):
|
405 |
"""Add the user's prompt to the two model's history and disable further submission."""
|
406 |
client = global_controller_client.fork()
|
@@ -482,6 +490,9 @@ def make_energy_vote_func(is_worth: bool):
|
|
482 |
return energy_vote_func
|
483 |
|
484 |
def play_again():
|
|
|
|
|
|
|
485 |
return [
|
486 |
# Clear chatbot history
|
487 |
None, None,
|
@@ -491,8 +502,8 @@ def play_again():
|
|
491 |
gr.Markdown.update(value="", visible=False), gr.Markdown.update(value="", visible=False),
|
492 |
# Hide energy vote buttons and message
|
493 |
gr.Button.update(visible=False), gr.Button.update(visible=False), gr.Markdown.update(visible=False),
|
494 |
-
# Enable model preference dropdown
|
495 |
-
gr.Dropdown.update(interactive=True),
|
496 |
# Disable reset button
|
497 |
gr.Button.update(interactive=False, visible=False),
|
498 |
]
|
@@ -520,8 +531,7 @@ with gr.Blocks(css=custom_css) as block:
|
|
520 |
|
521 |
with gr.Row():
|
522 |
model_preference_dropdown = gr.Dropdown(
|
523 |
-
|
524 |
-
value=model_preference_dropdown_choices[0],
|
525 |
label="Prefer a specific model?",
|
526 |
interactive=True,
|
527 |
)
|
@@ -759,7 +769,7 @@ with gr.Blocks(css=custom_css) as block:
|
|
759 |
gr.Markdown(open("docs/leaderboard.md").read())
|
760 |
|
761 |
# Load the table on page load.
|
762 |
-
block.load(
|
763 |
|
764 |
|
765 |
if __name__ == "__main__":
|
|
|
1 |
from __future__ import annotations
|
2 |
|
3 |
+
import copy
|
4 |
import json
|
5 |
import random
|
6 |
import yaml
|
|
|
366 |
global_controller_client = ControllerClient(controller_addr=controller_addr, timeout=15)
|
367 |
|
368 |
# Load the list of models. To reload, the app should be restarted.
|
369 |
+
global_available_models = global_controller_client.get_available_models()
|
370 |
+
model_name_to_user_pref = {model: f"One is {model}" for model in global_available_models}
|
371 |
+
model_name_to_user_pref["Random"] = "Two random models"
|
372 |
+
user_pref_to_model_name = {v: k for k, v in model_name_to_user_pref.items()}
|
|
|
373 |
|
374 |
# Colosseum helper functions.
|
375 |
def enable_interact():
|
|
|
401 |
return f"<h2>That response <span class='red-text'>consumed {how_much} more energy</span> ({energy_a:,.0f} J vs. {energy_b:,.0f} J).</h2>"
|
402 |
|
403 |
# Colosseum event handlers
|
404 |
+
def on_load():
|
405 |
+
"""Intialize the dataframe, shuffle the model preference dropdown choices."""
|
406 |
+
dataframe = global_tbm.set_filter_get_df()
|
407 |
+
available_models = copy.deepcopy(global_available_models)
|
408 |
+
random.shuffle(available_models)
|
409 |
+
available_models.insert(0, "Random")
|
410 |
+
return dataframe, gr.Dropdown.update(choices=[model_name_to_user_pref[model] for model in available_models])
|
411 |
+
|
412 |
def add_prompt_disable_submit(prompt, history_a, history_b):
|
413 |
"""Add the user's prompt to the two model's history and disable further submission."""
|
414 |
client = global_controller_client.fork()
|
|
|
490 |
return energy_vote_func
|
491 |
|
492 |
def play_again():
|
493 |
+
available_models = copy.deepcopy(global_available_models)
|
494 |
+
random.shuffle(available_models)
|
495 |
+
available_models.insert(0, "Random")
|
496 |
return [
|
497 |
# Clear chatbot history
|
498 |
None, None,
|
|
|
502 |
gr.Markdown.update(value="", visible=False), gr.Markdown.update(value="", visible=False),
|
503 |
# Hide energy vote buttons and message
|
504 |
gr.Button.update(visible=False), gr.Button.update(visible=False), gr.Markdown.update(visible=False),
|
505 |
+
# Enable model preference dropdown and shuffle choices
|
506 |
+
gr.Dropdown.update(choices=[model_name_to_user_pref[model] for model in available_models], interactive=True),
|
507 |
# Disable reset button
|
508 |
gr.Button.update(interactive=False, visible=False),
|
509 |
]
|
|
|
531 |
|
532 |
with gr.Row():
|
533 |
model_preference_dropdown = gr.Dropdown(
|
534 |
+
value="Two random models",
|
|
|
535 |
label="Prefer a specific model?",
|
536 |
interactive=True,
|
537 |
)
|
|
|
769 |
gr.Markdown(open("docs/leaderboard.md").read())
|
770 |
|
771 |
# Load the table on page load.
|
772 |
+
block.load(on_load, outputs=[dataframe, model_preference_dropdown], queue=False)
|
773 |
|
774 |
|
775 |
if __name__ == "__main__":
|