mlabonne commited on
Commit
ca8f9e2
·
verified ·
1 Parent(s): e9aa60b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -22,6 +22,7 @@ import gradio as gr
22
  def generate_regex(board):
23
  """
24
  Generate regular expression for legal moves.
 
25
  """
26
  legal_moves = list(board.legal_moves)
27
  move_strings = [board.san(move) for move in legal_moves]
@@ -171,7 +172,9 @@ def save_pgn(final_pgn, file_name, auth_token):
171
 
172
 
173
  def download_file(base_url, file_name):
174
- # Unique query parameter to bypass cache (using a timestamp)
 
 
175
  timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
176
  url = f"{base_url}?ts={timestamp}"
177
 
@@ -191,6 +194,9 @@ def download_file(base_url, file_name):
191
 
192
 
193
  def get_leaderboard():
 
 
 
194
  url = f"https://gist.githubusercontent.com/chessllm/{LEAD_GIST_ID}/raw"
195
  download_file(url, "chessllm_leaderboard.csv")
196
  return pd.read_csv("chessllm_leaderboard.csv")
@@ -281,7 +287,7 @@ def update(model_id_white, model_id_black):
281
 
282
  # Generate move
283
  start_time = time.time()
284
- guided = generate.regex(current_model, regex_pattern, max_tokens=10)(prompt)
285
  end_time = time.time()
286
  move_duration = end_time - start_time
287
 
@@ -437,7 +443,7 @@ title = """
437
  </div>
438
  """
439
 
440
- with gr.Blocks() as demo:
441
  gr.Markdown(title)
442
  with gr.Row():
443
  model_id_white = gr.Textbox(label="White Model ID", value="mlabonne/chesspythia-70m")
 
22
  def generate_regex(board):
23
  """
24
  Generate regular expression for legal moves.
25
+ Based on https://gist.github.com/903124/cfbefa24da95e2316e0d5e8ef8ed360d by @903124S.
26
  """
27
  legal_moves = list(board.legal_moves)
28
  move_strings = [board.san(move) for move in legal_moves]
 
172
 
173
 
174
  def download_file(base_url, file_name):
175
+ """
176
+ Helper function to download a file.
177
+ """
178
  timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
179
  url = f"{base_url}?ts={timestamp}"
180
 
 
194
 
195
 
196
  def get_leaderboard():
197
+ """
198
+ Wrapper to download the leaderboard and update the Gradio Dataframe.
199
+ """
200
  url = f"https://gist.githubusercontent.com/chessllm/{LEAD_GIST_ID}/raw"
201
  download_file(url, "chessllm_leaderboard.csv")
202
  return pd.read_csv("chessllm_leaderboard.csv")
 
287
 
288
  # Generate move
289
  start_time = time.time()
290
+ guided = generate.regex(current_model, regex_pattern)(prompt)
291
  end_time = time.time()
292
  move_duration = end_time - start_time
293
 
 
443
  </div>
444
  """
445
 
446
+ with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
447
  gr.Markdown(title)
448
  with gr.Row():
449
  model_id_white = gr.Textbox(label="White Model ID", value="mlabonne/chesspythia-70m")