Spaces:
Running
Running
Fixed human player
Browse files
app.py
CHANGED
@@ -232,25 +232,32 @@ def setup_player_config(
|
|
232 |
player_type: str, player_model: str, player_id: str
|
233 |
) -> Dict[str, Any]:
|
234 |
"""Map dropdown selection to agent config for the runner."""
|
235 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
236 |
return {"type": "random"}
|
237 |
|
238 |
-
if
|
239 |
return {"type": "human"}
|
240 |
|
241 |
if (
|
242 |
-
|
243 |
and (
|
244 |
-
|
245 |
-
or
|
246 |
)
|
247 |
):
|
248 |
-
model_id =
|
249 |
if BACKEND_SYSTEM_AVAILABLE and model_id in HUGGINGFACE_MODELS:
|
250 |
return {"type": "llm", "model": model_id}
|
251 |
|
252 |
if (
|
253 |
-
|
254 |
and player_model in HUGGINGFACE_MODELS
|
255 |
and BACKEND_SYSTEM_AVAILABLE
|
256 |
):
|
@@ -544,14 +551,18 @@ with gr.Blocks() as interface:
|
|
544 |
|
545 |
def player_selector_block(label: str):
|
546 |
gr.Markdown(f"### {label}")
|
547 |
-
|
548 |
-
|
|
|
549 |
for key in config["player_config"]["player_types"]
|
550 |
]
|
|
|
|
|
|
|
551 |
dd_type = gr.Dropdown(
|
552 |
-
choices=
|
553 |
label=f"{label} Type",
|
554 |
-
value=
|
555 |
)
|
556 |
dd_model = gr.Dropdown(
|
557 |
choices=config["player_config"]["available_models"],
|
@@ -565,13 +576,17 @@ with gr.Blocks() as interface:
|
|
565 |
p2_type, p2_model = player_selector_block("Player 1")
|
566 |
|
567 |
def _vis(player_type: str):
|
|
|
|
|
|
|
|
|
568 |
is_llm = (
|
569 |
-
|
570 |
or (
|
571 |
-
|
572 |
and (
|
573 |
-
|
574 |
-
or
|
575 |
)
|
576 |
)
|
577 |
)
|
@@ -639,7 +654,12 @@ with gr.Blocks() as interface:
|
|
639 |
|
640 |
def check_for_human_players(p1_type, p2_type):
|
641 |
"""Show/hide interactive controls based on player types."""
|
642 |
-
|
|
|
|
|
|
|
|
|
|
|
643 |
return (
|
644 |
gr.update(visible=has_human), # interactive_panel
|
645 |
gr.update(visible=has_human), # start_interactive_btn
|
@@ -676,20 +696,27 @@ with gr.Blocks() as interface:
|
|
676 |
from ui.gradio_config_generator import start_game_interactive
|
677 |
import time
|
678 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
679 |
# Use timestamp as seed
|
680 |
seed = int(time.time() * 1000) % (2**31 - 1)
|
681 |
|
682 |
log, state, legal_p0, legal_p1 = start_game_interactive(
|
683 |
-
game_name=
|
684 |
-
player1_type=
|
685 |
-
player2_type=
|
686 |
player1_model=p1_model,
|
687 |
player2_model=p2_model,
|
688 |
rounds=rounds,
|
689 |
seed=seed,
|
690 |
-
)
|
691 |
-
|
692 |
-
# Update dropdowns with legal actions
|
693 |
p0_choices = [(action, label) for action, label in legal_p0]
|
694 |
p1_choices = [(action, label) for action, label in legal_p1]
|
695 |
|
|
|
232 |
player_type: str, player_model: str, player_id: str
|
233 |
) -> Dict[str, Any]:
|
234 |
"""Map dropdown selection to agent config for the runner."""
|
235 |
+
# Create a temporary config to get the display-to-key mapping
|
236 |
+
temp_config = create_player_config()
|
237 |
+
display_to_key = {v: k for k, v in temp_config["player_config"]["player_type_display"].items()}
|
238 |
+
|
239 |
+
# Map display label back to internal key
|
240 |
+
internal_key = display_to_key.get(player_type, player_type)
|
241 |
+
|
242 |
+
if internal_key == "random_bot":
|
243 |
return {"type": "random"}
|
244 |
|
245 |
+
if internal_key == "human":
|
246 |
return {"type": "human"}
|
247 |
|
248 |
if (
|
249 |
+
internal_key
|
250 |
and (
|
251 |
+
internal_key.startswith("llm_")
|
252 |
+
or internal_key.startswith("hf_")
|
253 |
)
|
254 |
):
|
255 |
+
model_id = internal_key.split("_", 1)[1]
|
256 |
if BACKEND_SYSTEM_AVAILABLE and model_id in HUGGINGFACE_MODELS:
|
257 |
return {"type": "llm", "model": model_id}
|
258 |
|
259 |
if (
|
260 |
+
internal_key == "llm"
|
261 |
and player_model in HUGGINGFACE_MODELS
|
262 |
and BACKEND_SYSTEM_AVAILABLE
|
263 |
):
|
|
|
551 |
|
552 |
def player_selector_block(label: str):
|
553 |
gr.Markdown(f"### {label}")
|
554 |
+
# Create display choices (what user sees)
|
555 |
+
display_choices = [
|
556 |
+
config["player_config"]["player_type_display"][key]
|
557 |
for key in config["player_config"]["player_types"]
|
558 |
]
|
559 |
+
# Set default to first display choice
|
560 |
+
default_choice = display_choices[0] if display_choices else None
|
561 |
+
|
562 |
dd_type = gr.Dropdown(
|
563 |
+
choices=display_choices,
|
564 |
label=f"{label} Type",
|
565 |
+
value=default_choice,
|
566 |
)
|
567 |
dd_model = gr.Dropdown(
|
568 |
choices=config["player_config"]["available_models"],
|
|
|
576 |
p2_type, p2_model = player_selector_block("Player 1")
|
577 |
|
578 |
def _vis(player_type: str):
|
579 |
+
# Map display label back to internal key
|
580 |
+
display_to_key = {v: k for k, v in config["player_config"]["player_type_display"].items()}
|
581 |
+
internal_key = display_to_key.get(player_type, player_type)
|
582 |
+
|
583 |
is_llm = (
|
584 |
+
internal_key == "llm"
|
585 |
or (
|
586 |
+
internal_key
|
587 |
and (
|
588 |
+
internal_key.startswith("llm_")
|
589 |
+
or internal_key.startswith("hf_")
|
590 |
)
|
591 |
)
|
592 |
)
|
|
|
654 |
|
655 |
def check_for_human_players(p1_type, p2_type):
|
656 |
"""Show/hide interactive controls based on player types."""
|
657 |
+
# Map display labels back to internal keys
|
658 |
+
display_to_key = {v: k for k, v in config["player_config"]["player_type_display"].items()}
|
659 |
+
p1_key = display_to_key.get(p1_type, p1_type)
|
660 |
+
p2_key = display_to_key.get(p2_type, p2_type)
|
661 |
+
|
662 |
+
has_human = (p1_key == "human" or p2_key == "human")
|
663 |
return (
|
664 |
gr.update(visible=has_human), # interactive_panel
|
665 |
gr.update(visible=has_human), # start_interactive_btn
|
|
|
696 |
from ui.gradio_config_generator import start_game_interactive
|
697 |
import time
|
698 |
|
699 |
+
# Map display labels back to internal keys
|
700 |
+
display_to_key = {v: k for k, v in config["player_config"]["player_type_display"].items()}
|
701 |
+
p1_key = display_to_key.get(p1_type, p1_type)
|
702 |
+
p2_key = display_to_key.get(p2_type, p2_type)
|
703 |
+
|
704 |
+
# Map display game name back to internal key if needed
|
705 |
+
game_display_to_key = config.get("game_display_to_key", {})
|
706 |
+
internal_game = game_display_to_key.get(game_name, game_name)
|
707 |
+
|
708 |
# Use timestamp as seed
|
709 |
seed = int(time.time() * 1000) % (2**31 - 1)
|
710 |
|
711 |
log, state, legal_p0, legal_p1 = start_game_interactive(
|
712 |
+
game_name=internal_game,
|
713 |
+
player1_type=p1_key,
|
714 |
+
player2_type=p2_key,
|
715 |
player1_model=p1_model,
|
716 |
player2_model=p2_model,
|
717 |
rounds=rounds,
|
718 |
seed=seed,
|
719 |
+
) # Update dropdowns with legal actions
|
|
|
|
|
720 |
p0_choices = [(action, label) for action, label in legal_p0]
|
721 |
p1_choices = [(action, label) for action, label in legal_p1]
|
722 |
|