zhiminy commited on
Commit
d1e1e5c
·
1 Parent(s): cb8a7a8
Files changed (1) hide show
  1. app.py +25 -16
app.py CHANGED
@@ -32,6 +32,9 @@ openai_client = OpenAI(api_key=api_key, base_url=base_url)
32
  # Timeout in seconds for model responses
33
  TIMEOUT = 90
34
 
 
 
 
35
  # Hint string constant
36
  SHOW_HINT_STRING = True # Set to False to hide the hint string altogether
37
  HINT_STRING = "Once signed in, your votes will be recorded securely."
@@ -307,7 +310,7 @@ def format_conversation_history(conversation_history):
307
  return formatted_text
308
 
309
 
310
- def save_content_to_hf(vote_data, repo_name, folder_name, file_name, token=None):
311
  """
312
  Save feedback content to Hugging Face repository.
313
  """
@@ -318,7 +321,7 @@ def save_content_to_hf(vote_data, repo_name, folder_name, file_name, token=None)
318
  file_like_object = io.BytesIO(json_content)
319
 
320
  # Define the path in the repository
321
- filename = f"{folder_name}/{file_name}.json"
322
 
323
  # Ensure the user is authenticated with HF
324
  if token is None:
@@ -336,9 +339,20 @@ def save_content_to_hf(vote_data, repo_name, folder_name, file_name, token=None)
336
  )
337
 
338
 
339
- def load_content_from_hf(repo_name="SWE-Arena/model_votes"):
 
 
 
 
 
 
 
 
 
 
 
340
  """
341
- Read feedback content from a Hugging Face repository based on the current year.
342
 
343
  Args:
344
  repo_name (str): Hugging Face repository name.
@@ -347,14 +361,12 @@ def load_content_from_hf(repo_name="SWE-Arena/model_votes"):
347
  list: Aggregated feedback data read from the repository.
348
  """
349
  vote_data = []
350
- year = str(datetime.now().year)
351
-
352
  try:
353
  api = HfApi()
354
  # List all files in the repository
355
  for file in api.list_repo_files(repo_id=repo_name, repo_type="dataset"):
356
- # Filter files by current year
357
- if year not in file:
358
  continue
359
  # Download and aggregate data
360
  local_path = hf_hub_download(
@@ -426,7 +438,7 @@ def get_leaderboard_data(vote_entry=None, use_cache=True):
426
  )
427
 
428
  # Load conversation data from the Hugging Face repository
429
- conversation_data = load_content_from_hf("SWE-Arena/model_conversations")
430
  conversation_df = pd.DataFrame(conversation_data)
431
 
432
  # Merge vote data with conversation data
@@ -1391,14 +1403,12 @@ with gr.Blocks(js=clickable_links_js) as app:
1391
  "winner": winner_model,
1392
  }
1393
 
1394
- # Get the current year
1395
- now = datetime.now()
1396
- folder_name = now.year
1397
- file_name = now.strftime("%Y%m%d_%H%M%S")
1398
 
1399
  # Save feedback back to the Hugging Face dataset
1400
  save_content_to_hf(
1401
- vote_entry, "SWE-Arena/model_votes", folder_name, file_name, token
1402
  )
1403
 
1404
  conversation_state["right_chat"][0]["content"] = conversation_state[
@@ -1411,8 +1421,7 @@ with gr.Blocks(js=clickable_links_js) as app:
1411
  # Save conversations back to the Hugging Face dataset
1412
  save_content_to_hf(
1413
  conversation_state,
1414
- "SWE-Arena/model_conversations",
1415
- folder_name,
1416
  file_name,
1417
  token,
1418
  )
 
32
  # Timeout in seconds for model responses
33
  TIMEOUT = 90
34
 
35
+ # Leaderboard update time frame in days
36
+ LEADERBOARD_UPDATE_TIME_FRAME_DAYS = 365
37
+
38
  # Hint string constant
39
  SHOW_HINT_STRING = True # Set to False to hide the hint string altogether
40
  HINT_STRING = "Once signed in, your votes will be recorded securely."
 
310
  return formatted_text
311
 
312
 
313
+ def save_content_to_hf(vote_data, repo_name, file_name, token=None):
314
  """
315
  Save feedback content to Hugging Face repository.
316
  """
 
321
  file_like_object = io.BytesIO(json_content)
322
 
323
  # Define the path in the repository
324
+ filename = f"{file_name}.json"
325
 
326
  # Ensure the user is authenticated with HF
327
  if token is None:
 
339
  )
340
 
341
 
342
+ def is_file_within_time_frame(file_path, days):
343
+ try:
344
+ # Extract timestamp from filename
345
+ timestamp_str = file_path.split("/")[-1].split(".")[0]
346
+ file_datetime = datetime.strptime(timestamp_str, "%Y%m%d_%H%M%S")
347
+ time_diff = datetime.now() - file_datetime
348
+ return time_diff.days <= days
349
+ except:
350
+ return False
351
+
352
+
353
+ def load_content_from_hf(repo_name="SWE-Arena/vote_metadata"):
354
  """
355
+ Read feedback content from a Hugging Face repository within the last LEADERBOARD_UPDATE_TIME_FRAME_DAYS days.
356
 
357
  Args:
358
  repo_name (str): Hugging Face repository name.
 
361
  list: Aggregated feedback data read from the repository.
362
  """
363
  vote_data = []
 
 
364
  try:
365
  api = HfApi()
366
  # List all files in the repository
367
  for file in api.list_repo_files(repo_id=repo_name, repo_type="dataset"):
368
+ # Filter files by last LEADERBOARD_UPDATE_TIME_FRAME_DAYS days
369
+ if not is_file_within_time_frame(file, LEADERBOARD_UPDATE_TIME_FRAME_DAYS):
370
  continue
371
  # Download and aggregate data
372
  local_path = hf_hub_download(
 
438
  )
439
 
440
  # Load conversation data from the Hugging Face repository
441
+ conversation_data = load_content_from_hf("SWE-Arena/conversation_metadata")
442
  conversation_df = pd.DataFrame(conversation_data)
443
 
444
  # Merge vote data with conversation data
 
1403
  "winner": winner_model,
1404
  }
1405
 
1406
+ # Get the current datetime for file naming
1407
+ file_name = f"swe-model-arena/{datetime.now().strftime('%Y%m%d_%H%M%S')}"
 
 
1408
 
1409
  # Save feedback back to the Hugging Face dataset
1410
  save_content_to_hf(
1411
+ vote_entry, "SWE-Arena/vote_metadata", file_name, token
1412
  )
1413
 
1414
  conversation_state["right_chat"][0]["content"] = conversation_state[
 
1421
  # Save conversations back to the Hugging Face dataset
1422
  save_content_to_hf(
1423
  conversation_state,
1424
+ "SWE-Arena/conversation_metadata",
 
1425
  file_name,
1426
  token,
1427
  )