Commit
·
df06d5c
1
Parent(s):
cfa5138
Handling missing data
Browse files
app.py
CHANGED
|
@@ -1,11 +1,12 @@
|
|
| 1 |
-
import
|
|
|
|
| 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 |
|
| 10 |
from about import ABOUT_INTRO, ABOUT_TEXT, FAQS, SUBMIT_INSTRUCTIONS
|
| 11 |
from constants import (
|
|
@@ -52,7 +53,12 @@ def get_leaderboard_object(assay: str | None = None):
|
|
| 52 |
filter_columns.append("property")
|
| 53 |
# Bug: Can't leave search_columns empty because then it says "Column None not found in headers"
|
| 54 |
# Note(Lood): Would be nice to make it clear that the Search Column is searching on model name
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
lb = Leaderboard(
|
| 57 |
value=format_leaderboard_table(df_results=current_dataframe, assay=assay),
|
| 58 |
datatype=["str", "str", "str", "number", "str"],
|
|
@@ -68,16 +74,18 @@ def get_leaderboard_object(assay: str | None = None):
|
|
| 68 |
|
| 69 |
|
| 70 |
def refresh_overall_leaderboard():
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
return format_leaderboard_table(df_results=current_dataframe)
|
| 75 |
|
| 76 |
|
| 77 |
# Initialize global dataframe
|
| 78 |
-
|
| 79 |
-
current_dataframe = pd.read_csv("debug-current-results.csv")
|
| 80 |
-
|
| 81 |
|
| 82 |
# Make font size bigger using gradio theme
|
| 83 |
with gr.Blocks(theme=gr.themes.Default(text_size=sizes.text_lg)) as demo:
|
|
|
|
| 1 |
+
import time
|
| 2 |
+
|
| 3 |
import pandas as pd
|
| 4 |
import gradio as gr
|
| 5 |
from gradio.themes.utils import sizes
|
| 6 |
from gradio_leaderboard import Leaderboard
|
| 7 |
from dotenv import load_dotenv
|
| 8 |
|
| 9 |
+
load_dotenv() # Load environment variables from .env file (before imports)
|
| 10 |
|
| 11 |
from about import ABOUT_INTRO, ABOUT_TEXT, FAQS, SUBMIT_INSTRUCTIONS
|
| 12 |
from constants import (
|
|
|
|
| 53 |
filter_columns.append("property")
|
| 54 |
# Bug: Can't leave search_columns empty because then it says "Column None not found in headers"
|
| 55 |
# Note(Lood): Would be nice to make it clear that the Search Column is searching on model name
|
| 56 |
+
try:
|
| 57 |
+
current_dataframe = pd.read_csv("debug-current-results.csv")
|
| 58 |
+
except (pd.errors.EmptyDataError, pd.errors.ParserError):
|
| 59 |
+
# Return empty dataframe as fallback
|
| 60 |
+
print("Fallback: Returning empty dataframe as it doesn't exist yet")
|
| 61 |
+
current_dataframe = pd.DataFrame(columns=LEADERBOARD_COLUMNS_RENAME.values())
|
| 62 |
lb = Leaderboard(
|
| 63 |
value=format_leaderboard_table(df_results=current_dataframe, assay=assay),
|
| 64 |
datatype=["str", "str", "str", "number", "str"],
|
|
|
|
| 74 |
|
| 75 |
|
| 76 |
def refresh_overall_leaderboard():
|
| 77 |
+
# Handle race condition where file is being written while we read it
|
| 78 |
+
try:
|
| 79 |
+
current_dataframe = pd.read_csv("debug-current-results.csv")
|
| 80 |
+
except (pd.errors.EmptyDataError, pd.errors.ParserError):
|
| 81 |
+
# Return empty dataframe with required columns as fallback
|
| 82 |
+
print("Fallback: Returning empty dataframe as it doesn't exist yet")
|
| 83 |
+
current_dataframe = pd.DataFrame(columns=LEADERBOARD_COLUMNS_RENAME.values())
|
| 84 |
return format_leaderboard_table(df_results=current_dataframe)
|
| 85 |
|
| 86 |
|
| 87 |
# Initialize global dataframe
|
| 88 |
+
time.sleep(2) # Give the outer thread time to create the file at the start
|
|
|
|
|
|
|
| 89 |
|
| 90 |
# Make font size bigger using gradio theme
|
| 91 |
with gr.Blocks(theme=gr.themes.Default(text_size=sizes.text_lg)) as demo:
|