Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -21,13 +21,6 @@ def extract_table_from_markdown(markdown_text, table_start):
|
|
21 |
table_content.append(line)
|
22 |
return '\n'.join(table_content)
|
23 |
|
24 |
-
def parse_markdown_link(text):
|
25 |
-
"""Parse a Markdown link and return the display text and URL."""
|
26 |
-
match = re.match(r'\[(.*?)\]\((.*?)\)', text)
|
27 |
-
if match:
|
28 |
-
return match.group(1), match.group(2)
|
29 |
-
return text, None
|
30 |
-
|
31 |
def markdown_table_to_df(table_content):
|
32 |
"""Convert markdown table to pandas DataFrame."""
|
33 |
# Split the table content into lines
|
@@ -41,17 +34,14 @@ def markdown_table_to_df(table_content):
|
|
41 |
for line in lines[2:]: # Skip the header separator line
|
42 |
row = [cell.strip() for cell in line.split('|') if cell.strip()]
|
43 |
if row and len(row) == len(headers): # Ensure row has the correct number of columns
|
44 |
-
|
45 |
-
model_name, url = parse_markdown_link(row[0])
|
46 |
-
row[0] = model_name
|
47 |
-
data.append(row + [url]) # Add URL as a new column
|
48 |
|
49 |
# Create DataFrame
|
50 |
-
df = pd.DataFrame(data, columns=headers
|
51 |
|
52 |
# Convert numeric columns to float
|
53 |
for col in df.columns:
|
54 |
-
if col not in ["Model Name", "Publisher", "Open?", "Basemodel", "Matryoshka"
|
55 |
df[col] = pd.to_numeric(df[col], errors='coerce')
|
56 |
|
57 |
return df
|
@@ -70,29 +60,19 @@ def display_leaderboard(df):
|
|
70 |
present_non_benchmark_cols = [col for col in POSSIBLE_NON_BENCHMARK_COLS if col in df.columns]
|
71 |
|
72 |
# Add filters
|
73 |
-
columns_to_filter = [col for col in df.columns if col not in present_non_benchmark_cols
|
74 |
selected_columns = st.multiselect("Select benchmarks to display:", columns_to_filter, default=columns_to_filter)
|
75 |
|
76 |
# Filter dataframe
|
77 |
df_display = df[present_non_benchmark_cols + selected_columns]
|
78 |
|
79 |
-
#
|
80 |
-
|
81 |
-
|
82 |
-
# Create clickable links in the Model Name column
|
83 |
-
df_display_with_links['Model Name'] = df_display_with_links.apply(
|
84 |
-
lambda row: f'<a href="{row["URL"]}" target="_blank">{row["Model Name"]}</a>' if pd.notnull(row["URL"]) else row["Model Name"],
|
85 |
-
axis=1
|
86 |
-
)
|
87 |
-
|
88 |
-
# Display dataframe with clickable links
|
89 |
-
st.write(df_display_with_links.to_html(escape=False, index=False), unsafe_allow_html=True)
|
90 |
|
91 |
# Download buttons
|
92 |
csv = df_display.to_csv(index=False)
|
93 |
st.download_button(label="Download as CSV", data=csv, file_name="leaderboard.csv", mime="text/csv")
|
94 |
|
95 |
-
|
96 |
def display_evaluation():
|
97 |
"""Display the evaluation section."""
|
98 |
st.header("🧪 Evaluation")
|
|
|
21 |
table_content.append(line)
|
22 |
return '\n'.join(table_content)
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
def markdown_table_to_df(table_content):
|
25 |
"""Convert markdown table to pandas DataFrame."""
|
26 |
# Split the table content into lines
|
|
|
34 |
for line in lines[2:]: # Skip the header separator line
|
35 |
row = [cell.strip() for cell in line.split('|') if cell.strip()]
|
36 |
if row and len(row) == len(headers): # Ensure row has the correct number of columns
|
37 |
+
data.append(row)
|
|
|
|
|
|
|
38 |
|
39 |
# Create DataFrame
|
40 |
+
df = pd.DataFrame(data, columns=headers)
|
41 |
|
42 |
# Convert numeric columns to float
|
43 |
for col in df.columns:
|
44 |
+
if col not in ["Model Name", "Publisher", "Open?", "Basemodel", "Matryoshka"]:
|
45 |
df[col] = pd.to_numeric(df[col], errors='coerce')
|
46 |
|
47 |
return df
|
|
|
60 |
present_non_benchmark_cols = [col for col in POSSIBLE_NON_BENCHMARK_COLS if col in df.columns]
|
61 |
|
62 |
# Add filters
|
63 |
+
columns_to_filter = [col for col in df.columns if col not in present_non_benchmark_cols]
|
64 |
selected_columns = st.multiselect("Select benchmarks to display:", columns_to_filter, default=columns_to_filter)
|
65 |
|
66 |
# Filter dataframe
|
67 |
df_display = df[present_non_benchmark_cols + selected_columns]
|
68 |
|
69 |
+
# Display dataframe
|
70 |
+
st.dataframe(df_display.style.format("{:.4f}", subset=[col for col in df_display.columns if df_display[col].dtype == 'float64']))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
# Download buttons
|
73 |
csv = df_display.to_csv(index=False)
|
74 |
st.download_button(label="Download as CSV", data=csv, file_name="leaderboard.csv", mime="text/csv")
|
75 |
|
|
|
76 |
def display_evaluation():
|
77 |
"""Display the evaluation section."""
|
78 |
st.header("🧪 Evaluation")
|