Spaces:
Running
Running
Updated to use the current time as the random seed
Browse filesSo when we select a random agent, we get different moves every time
app.py
CHANGED
@@ -31,7 +31,7 @@ import logging
|
|
31 |
logging.basicConfig(level=logging.INFO)
|
32 |
log = logging.getLogger("arena_space")
|
33 |
|
34 |
-
# Optional transformers import
|
35 |
try:
|
36 |
from transformers import pipeline # noqa: F401
|
37 |
except Exception:
|
@@ -126,7 +126,7 @@ def _get_game_display_mapping() -> Dict[str, str]:
|
|
126 |
display = key.replace("_", " ").title()
|
127 |
mapping[key] = display
|
128 |
return mapping
|
129 |
-
|
130 |
|
131 |
# -----------------------------------------------------------------------------
|
132 |
# DB helpers
|
@@ -334,6 +334,7 @@ def play_game(
|
|
334 |
player1_model: str | None = None,
|
335 |
player2_model: str | None = None,
|
336 |
rounds: int = 1,
|
|
|
337 |
) -> str:
|
338 |
if game_name == "No Games Found":
|
339 |
return "No games available. Please add game databases."
|
@@ -362,10 +363,14 @@ def play_game(
|
|
362 |
if player2_type in display_to_key:
|
363 |
player2_type = display_to_key[player2_type]
|
364 |
|
|
|
365 |
try:
|
366 |
from ui.gradio_config_generator import (
|
367 |
run_game_with_existing_infrastructure,
|
368 |
)
|
|
|
|
|
|
|
369 |
result = run_game_with_existing_infrastructure(
|
370 |
game_name=game_name,
|
371 |
player1_type=player1_type,
|
@@ -373,7 +378,7 @@ def play_game(
|
|
373 |
player1_model=player1_model,
|
374 |
player2_model=player2_model,
|
375 |
rounds=rounds,
|
376 |
-
seed=
|
377 |
)
|
378 |
return result
|
379 |
except Exception as e:
|
@@ -588,6 +593,7 @@ with gr.Blocks() as interface:
|
|
588 |
p1_model,
|
589 |
p2_model,
|
590 |
rounds_slider,
|
|
|
591 |
],
|
592 |
outputs=[game_output],
|
593 |
)
|
@@ -708,4 +714,4 @@ with gr.Blocks() as interface:
|
|
708 |
|
709 |
# Local run only. On Spaces, the runtime will serve `interface` automatically.
|
710 |
if __name__ == "__main__":
|
711 |
-
interface.launch(server_name="0.0.0.0", server_port=None, show_api=False)
|
|
|
31 |
logging.basicConfig(level=logging.INFO)
|
32 |
log = logging.getLogger("arena_space")
|
33 |
|
34 |
+
# Optional transformers import
|
35 |
try:
|
36 |
from transformers import pipeline # noqa: F401
|
37 |
except Exception:
|
|
|
126 |
display = key.replace("_", " ").title()
|
127 |
mapping[key] = display
|
128 |
return mapping
|
129 |
+
|
130 |
|
131 |
# -----------------------------------------------------------------------------
|
132 |
# DB helpers
|
|
|
334 |
player1_model: str | None = None,
|
335 |
player2_model: str | None = None,
|
336 |
rounds: int = 1,
|
337 |
+
seed: int | None = None,
|
338 |
) -> str:
|
339 |
if game_name == "No Games Found":
|
340 |
return "No games available. Please add game databases."
|
|
|
363 |
if player2_type in display_to_key:
|
364 |
player2_type = display_to_key[player2_type]
|
365 |
|
366 |
+
import time
|
367 |
try:
|
368 |
from ui.gradio_config_generator import (
|
369 |
run_game_with_existing_infrastructure,
|
370 |
)
|
371 |
+
# Use a random seed if not provided
|
372 |
+
if seed is None:
|
373 |
+
seed = int(time.time() * 1000) % (2**31 - 1)
|
374 |
result = run_game_with_existing_infrastructure(
|
375 |
game_name=game_name,
|
376 |
player1_type=player1_type,
|
|
|
378 |
player1_model=player1_model,
|
379 |
player2_model=player2_model,
|
380 |
rounds=rounds,
|
381 |
+
seed=seed,
|
382 |
)
|
383 |
return result
|
384 |
except Exception as e:
|
|
|
593 |
p1_model,
|
594 |
p2_model,
|
595 |
rounds_slider,
|
596 |
+
# No seed input from user; will default to None
|
597 |
],
|
598 |
outputs=[game_output],
|
599 |
)
|
|
|
714 |
|
715 |
# Local run only. On Spaces, the runtime will serve `interface` automatically.
|
716 |
if __name__ == "__main__":
|
717 |
+
interface.launch(server_name="0.0.0.0", server_port=None, show_api=False)
|