loodvanniekerkginkgo commited on
Commit
cfa5138
·
1 Parent(s): a897a54

Fixed fillna anonymous, moved data fetching to utils.py

Browse files
Files changed (2) hide show
  1. app.py +7 -29
  2. utils.py +28 -2
app.py CHANGED
@@ -1,9 +1,9 @@
 
1
  import pandas as pd
2
  import gradio as gr
3
  from gradio.themes.utils import sizes
4
  from gradio_leaderboard import Leaderboard
5
  from dotenv import load_dotenv
6
- import contextlib
7
 
8
  load_dotenv() # Load environment variables from .env file
9
 
@@ -21,7 +21,7 @@ from constants import (
21
  SLACK_URL,
22
  )
23
  from submit import make_submission
24
- from utils import fetch_hf_results, show_output_box
25
 
26
 
27
  def format_leaderboard_table(df_results: pd.DataFrame, assay: str | None = None):
@@ -67,38 +67,16 @@ def get_leaderboard_object(assay: str | None = None):
67
  return lb
68
 
69
 
70
- # Initialize global dataframe
71
- fetch_hf_results()
72
- current_dataframe = pd.read_csv("debug-current-results.csv")
73
-
74
-
75
  def refresh_overall_leaderboard():
 
 
76
  current_dataframe = pd.read_csv("debug-current-results.csv")
77
  return format_leaderboard_table(df_results=current_dataframe)
78
 
79
 
80
- def fetch_latest_data(stop_event):
81
- import time
82
-
83
- while not stop_event.is_set():
84
- try:
85
- fetch_hf_results()
86
- except Exception as e:
87
- print(f"Error fetching latest data: {e}")
88
- time.sleep(3) # Fetch every 60 seconds
89
- print("Exiting data fetch thread")
90
-
91
-
92
- @contextlib.asynccontextmanager
93
- async def periodic_data_fetch(app):
94
- import threading
95
-
96
- event = threading.Event()
97
- t = threading.Thread(target=fetch_latest_data, args=(event,), daemon=True)
98
- t.start()
99
- yield
100
- event.set()
101
- t.join(3)
102
 
103
 
104
  # Make font size bigger using gradio theme
 
1
+ import os
2
  import pandas as pd
3
  import gradio as gr
4
  from gradio.themes.utils import sizes
5
  from gradio_leaderboard import Leaderboard
6
  from dotenv import load_dotenv
 
7
 
8
  load_dotenv() # Load environment variables from .env file
9
 
 
21
  SLACK_URL,
22
  )
23
  from submit import make_submission
24
+ from utils import fetch_hf_results, show_output_box, periodic_data_fetch
25
 
26
 
27
  def format_leaderboard_table(df_results: pd.DataFrame, assay: str | None = None):
 
67
  return lb
68
 
69
 
 
 
 
 
 
70
  def refresh_overall_leaderboard():
71
+ if not os.path.exists("debug-current-results.csv"):
72
+ fetch_hf_results() # Hope this doesn't cause race conditions with the main fetch_hf_results() thread
73
  current_dataframe = pd.read_csv("debug-current-results.csv")
74
  return format_leaderboard_table(df_results=current_dataframe)
75
 
76
 
77
+ # Initialize global dataframe
78
+ fetch_hf_results()
79
+ current_dataframe = pd.read_csv("debug-current-results.csv")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
 
81
 
82
  # Make font size bigger using gradio theme
utils.py CHANGED
@@ -1,3 +1,4 @@
 
1
  from datetime import datetime, timezone, timedelta
2
  import hashlib
3
  import os
@@ -66,8 +67,9 @@ def fetch_hf_results():
66
  df.loc[df["user"].isin(BASELINE_USERNAMES), "user"] = "Baseline"
67
  # Note: Could optionally add a column "is_baseline" to the dataframe to indicate whether the model is a baseline model or not. If things get crowded.
68
  # Anonymize the user column at this point (so note: users can submit anonymous / non-anonymous and we'll show their latest submission regardless)
69
- anon_rows = df["anonymous"].fillna(True)
70
- df.loc[anon_rows, "user"] = "anon-" + df.loc[anon_rows, "user"].apply(readable_hash)
 
71
 
72
  # Compare to previous dataframe
73
  if os.path.exists("debug-current-results.csv"):
@@ -78,6 +80,30 @@ def fetch_hf_results():
78
  df.to_csv("debug-current-results.csv", index=False)
79
 
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  # Readable hashing function similar to coolname or codenamize
82
  ADJECTIVES = [
83
  "ancient",
 
1
+ import contextlib
2
  from datetime import datetime, timezone, timedelta
3
  import hashlib
4
  import os
 
67
  df.loc[df["user"].isin(BASELINE_USERNAMES), "user"] = "Baseline"
68
  # Note: Could optionally add a column "is_baseline" to the dataframe to indicate whether the model is a baseline model or not. If things get crowded.
69
  # Anonymize the user column at this point (so note: users can submit anonymous / non-anonymous and we'll show their latest submission regardless)
70
+ df.loc[df["anonymous"], "user"] = "anon-" + df.loc[df["anonymous"], "user"].apply(
71
+ readable_hash
72
+ )
73
 
74
  # Compare to previous dataframe
75
  if os.path.exists("debug-current-results.csv"):
 
80
  df.to_csv("debug-current-results.csv", index=False)
81
 
82
 
83
+ def fetch_latest_data(stop_event):
84
+ import time
85
+
86
+ while not stop_event.is_set():
87
+ try:
88
+ fetch_hf_results()
89
+ except Exception as e:
90
+ print(f"Error fetching latest data: {e}")
91
+ time.sleep(3) # Fetch every 60 seconds
92
+ print("Exiting data fetch thread")
93
+
94
+
95
+ @contextlib.asynccontextmanager
96
+ async def periodic_data_fetch(app):
97
+ import threading
98
+
99
+ event = threading.Event()
100
+ t = threading.Thread(target=fetch_latest_data, args=(event,), daemon=True)
101
+ t.start()
102
+ yield
103
+ event.set()
104
+ t.join(3)
105
+
106
+
107
  # Readable hashing function similar to coolname or codenamize
108
  ADJECTIVES = [
109
  "ancient",