Joffrey THOMAS commited on
Commit
2eeeb39
·
1 Parent(s): 8665f5d

change server

Browse files
Files changed (1) hide show
  1. main.py +33 -15
main.py CHANGED
@@ -21,12 +21,24 @@ from poke_env import AccountConfiguration, ServerConfiguration
21
  # Import the actual agent classes
22
  from agents import OpenAIAgent, GeminiAgent, MistralAgent
23
 
24
- # --- Configuration ---
25
- CUSTOM_SERVER_URL = "wss://jofthomas.com/showdown/websocket"
26
- CUSTOM_ACTION_URL = 'https://play.pokemonshowdown.com/action.php?'
27
- CUSTOM_BATTLE_VIEW_URL_TEMPLATE = "https://jofthomas.com/play.pokemonshowdown.com/testclient.html#{battle_id}"
 
 
 
 
 
 
 
 
 
 
 
 
28
  custom_config = ServerConfiguration(CUSTOM_SERVER_URL, CUSTOM_ACTION_URL)
29
- DEFAULT_BATTLE_FORMAT = "gen9randombattle"
30
  LAST_ACTION_FILE = "last_action.txt" # --- ADDED FOR /last_action --- (Filename)
31
 
32
  # Define available agents with their corresponding classes
@@ -79,9 +91,7 @@ def get_active_battle(agent: Player):
79
  def create_battle_iframe(battle_id: str) -> str:
80
  """Creates JUST the HTML for the battle iframe tag."""
81
  print("Creating iframe content for battle ID: ", battle_id)
82
- # Use the official client URL unless you specifically need the test client
83
- # battle_url = f"https://play.pokemonshowdown.com/{battle_id}"
84
- battle_url = f"https://jofthomas.com/play.pokemonshowdown.com/testclient.html#{battle_id}" # Using your custom URL
85
 
86
  # Return ONLY the iframe tag with a class for styling
87
  return f"""
@@ -532,20 +542,26 @@ class ConnectionManager:
532
 
533
  manager = ConnectionManager()
534
 
 
 
 
 
 
 
 
 
535
  # --- API Routes ---
536
  @app.get("/", response_class=HTMLResponse)
537
  async def get_homepage():
538
- """Serves the main HTML page with WebSocket connection and improved styling."""
539
- # NOTE: Ensure the static path '/static/pokemon_huggingface.png' is correct
540
- # and the image exists in a 'static' folder next to your main.py
541
- # (Existing HTML content remains unchanged)
542
- return """
543
  <!DOCTYPE html>
544
  <html lang="en">
545
  <head>
546
  <meta charset="UTF-8">
547
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
548
- <title>Pokemon Battle Livestream</title>
549
  <link rel="preconnect" href="https://fonts.googleapis.com">
550
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
551
  <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;700&family=Press+Start+2P&display=swap" rel="stylesheet">
@@ -596,7 +612,7 @@ async def get_homepage():
596
  /* Idle Screen Specific Styling */
597
  .idle-container {
598
  /* Ensure the background covers the entire container */
599
- background-image: url('/static/pokemon_huggingface.png');
600
  background-size: cover;
601
  background-position: center;
602
  background-repeat: no-repeat;
@@ -717,6 +733,8 @@ async def get_homepage():
717
  </body>
718
  </html>
719
  """
 
 
720
 
721
  @app.get("/last_action", response_class=HTMLResponse)
722
  async def get_last_action():
 
21
  # Import the actual agent classes
22
  from agents import OpenAIAgent, GeminiAgent, MistralAgent
23
 
24
+ # --- Configuration (override via environment variables) ---
25
+ # Showdown WebSocket URL, e.g. wss://my-app.fly.dev/showdown/websocket
26
+ CUSTOM_SERVER_URL = os.environ.get(
27
+ "SHOWDOWN_WS_URL",
28
+ "wss://deploy-lingering-grove-7264.fly.dev/showdown/websocket",
29
+ )
30
+ # Action endpoint for poke-env (official login server is fine for custom servers)
31
+ CUSTOM_ACTION_URL = os.environ.get(
32
+ "SHOWDOWN_ACTION_URL",
33
+ "https://play.pokemonshowdown.com/action.php?",
34
+ )
35
+ # Battle iframe URL template — {battle_id} is replaced at runtime
36
+ CUSTOM_BATTLE_VIEW_URL_TEMPLATE = os.environ.get(
37
+ "BATTLE_VIEW_URL",
38
+ "https://deploy-lingering-grove-7264.fly.dev/#{battle_id}",
39
+ )
40
  custom_config = ServerConfiguration(CUSTOM_SERVER_URL, CUSTOM_ACTION_URL)
41
+ DEFAULT_BATTLE_FORMAT = os.environ.get("BATTLE_FORMAT", "gen9randombattle")
42
  LAST_ACTION_FILE = "last_action.txt" # --- ADDED FOR /last_action --- (Filename)
43
 
44
  # Define available agents with their corresponding classes
 
91
  def create_battle_iframe(battle_id: str) -> str:
92
  """Creates JUST the HTML for the battle iframe tag."""
93
  print("Creating iframe content for battle ID: ", battle_id)
94
+ battle_url = CUSTOM_BATTLE_VIEW_URL_TEMPLATE.format(battle_id=battle_id)
 
 
95
 
96
  # Return ONLY the iframe tag with a class for styling
97
  return f"""
 
542
 
543
  manager = ConnectionManager()
544
 
545
+ BACKGROUND_FILE = os.getenv('BACKGROUND_FILE', 'option1.jpg')
546
+ IDLE_BG_URL = f'/static/{BACKGROUND_FILE}'
547
+
548
+
549
+ def idle_background_url() -> str:
550
+ return IDLE_BG_URL
551
+
552
+
553
  # --- API Routes ---
554
  @app.get("/", response_class=HTMLResponse)
555
  async def get_homepage():
556
+ """Serves the main HTML page with WebSocket connection and improved styling."""
557
+ bg_url = idle_background_url()
558
+ html = """
 
 
559
  <!DOCTYPE html>
560
  <html lang="en">
561
  <head>
562
  <meta charset="UTF-8">
563
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
564
+ <title>PokéLLM Arena</title>
565
  <link rel="preconnect" href="https://fonts.googleapis.com">
566
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
567
  <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;700&family=Press+Start+2P&display=swap" rel="stylesheet">
 
612
  /* Idle Screen Specific Styling */
613
  .idle-container {
614
  /* Ensure the background covers the entire container */
615
+ background-image: url('__IDLE_BG_URL__');
616
  background-size: cover;
617
  background-position: center;
618
  background-repeat: no-repeat;
 
733
  </body>
734
  </html>
735
  """
736
+ return html.replace('__IDLE_BG_URL__', bg_url)
737
+
738
 
739
  @app.get("/last_action", response_class=HTMLResponse)
740
  async def get_last_action():