Spaces:
Sleeping
Sleeping
arunasrivastava
commited on
Commit
ยท
e61aa35
1
Parent(s):
5a74763
styled row and dropdown
Browse files
app.py
CHANGED
@@ -29,10 +29,15 @@ def load_leaderboard_data():
|
|
29 |
logging.error(f"Error loading leaderboard: {e}")
|
30 |
return pd.DataFrame()
|
31 |
|
32 |
-
def format_leaderboard_df(df):
|
33 |
if df.empty:
|
34 |
return df
|
35 |
|
|
|
|
|
|
|
|
|
|
|
36 |
display_df = pd.DataFrame({
|
37 |
"Model": df["model"],
|
38 |
"Average PER โฌ๏ธ": df["average_per"].apply(lambda x: f"{x:.4f}"),
|
@@ -41,11 +46,21 @@ def format_leaderboard_df(df):
|
|
41 |
"Submission Date": pd.to_datetime(df["submission_date"]).dt.strftime("%Y-%m-%d")
|
42 |
})
|
43 |
|
44 |
-
return display_df
|
45 |
|
46 |
def create_html_table(df):
|
47 |
return df.to_html(escape=False, index=False, classes="styled-table")
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
def submit_evaluation(model_name: str, submission_name: str, github_url: str) -> str:
|
50 |
if not model_name or not submission_name:
|
51 |
return "โ ๏ธ Please provide both model name and submission name."
|
@@ -136,7 +151,7 @@ with gr.Blocks(css="""
|
|
136 |
box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
|
137 |
}
|
138 |
.styled-table thead tr {
|
139 |
-
background
|
140 |
color: #ffffff;
|
141 |
text-align: left;
|
142 |
}
|
@@ -164,14 +179,30 @@ with gr.Blocks(css="""
|
|
164 |
""")
|
165 |
with gr.Tabs():
|
166 |
with gr.TabItem("๐ Leaderboard"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
leaderboard_html = gr.HTML(create_html_table(format_leaderboard_df(load_leaderboard_data())))
|
168 |
-
|
|
|
|
|
|
|
|
|
169 |
refresh_btn.click(
|
170 |
-
|
|
|
171 |
outputs=leaderboard_html
|
172 |
)
|
173 |
|
174 |
-
|
175 |
with gr.TabItem("๐ Submit Model"):
|
176 |
model_name = gr.Textbox(label="Model Name", placeholder="facebook/wav2vec2-lv-60-espeak-cv-ft")
|
177 |
submission_name = gr.Textbox(label="Submission Name", placeholder="My Model v1.0")
|
|
|
29 |
logging.error(f"Error loading leaderboard: {e}")
|
30 |
return pd.DataFrame()
|
31 |
|
32 |
+
def format_leaderboard_df(df, sort_by="pwed"):
|
33 |
if df.empty:
|
34 |
return df
|
35 |
|
36 |
+
# Sort the original dataframe first
|
37 |
+
sort_column = "average_per" if sort_by.lower() == "per" else "average_pwed"
|
38 |
+
df = df.sort_values(by=sort_column, ascending=True) # Ascending=True means smaller values at top
|
39 |
+
|
40 |
+
# Then create display dataframe from the sorted data
|
41 |
display_df = pd.DataFrame({
|
42 |
"Model": df["model"],
|
43 |
"Average PER โฌ๏ธ": df["average_per"].apply(lambda x: f"{x:.4f}"),
|
|
|
46 |
"Submission Date": pd.to_datetime(df["submission_date"]).dt.strftime("%Y-%m-%d")
|
47 |
})
|
48 |
|
49 |
+
return display_df
|
50 |
|
51 |
def create_html_table(df):
|
52 |
return df.to_html(escape=False, index=False, classes="styled-table")
|
53 |
|
54 |
+
def update_leaderboard(sort_option: str) -> str:
|
55 |
+
try:
|
56 |
+
df = load_leaderboard_data()
|
57 |
+
formatted_df = format_leaderboard_df(df, sort_option.lower())
|
58 |
+
return create_html_table(formatted_df)
|
59 |
+
except Exception as e:
|
60 |
+
logging.error(f"Error updating leaderboard: {e}")
|
61 |
+
return "Error updating leaderboard"
|
62 |
+
|
63 |
+
|
64 |
def submit_evaluation(model_name: str, submission_name: str, github_url: str) -> str:
|
65 |
if not model_name or not submission_name:
|
66 |
return "โ ๏ธ Please provide both model name and submission name."
|
|
|
151 |
box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
|
152 |
}
|
153 |
.styled-table thead tr {
|
154 |
+
background: linear-gradient(45deg, #092746, #073562, #0A648F);
|
155 |
color: #ffffff;
|
156 |
text-align: left;
|
157 |
}
|
|
|
179 |
""")
|
180 |
with gr.Tabs():
|
181 |
with gr.TabItem("๐ Leaderboard"):
|
182 |
+
with gr.Row(elem_classes="controls-row"):
|
183 |
+
# Controls side by side
|
184 |
+
sort_dropdown = gr.Dropdown(
|
185 |
+
choices=["PWED", "PER"],
|
186 |
+
value="PWED",
|
187 |
+
interactive=True,
|
188 |
+
scale=2,
|
189 |
+
container=False, # Removes the box around the dropdown
|
190 |
+
label=None # Removes the "Sort by" label
|
191 |
+
)
|
192 |
+
refresh_btn = gr.Button("Refresh ๐", scale=2) # Simplified button text
|
193 |
+
|
194 |
leaderboard_html = gr.HTML(create_html_table(format_leaderboard_df(load_leaderboard_data())))
|
195 |
+
sort_dropdown.change(
|
196 |
+
fn=update_leaderboard,
|
197 |
+
inputs=[sort_dropdown],
|
198 |
+
outputs=leaderboard_html
|
199 |
+
)
|
200 |
refresh_btn.click(
|
201 |
+
fn=update_leaderboard,
|
202 |
+
inputs=[sort_dropdown],
|
203 |
outputs=leaderboard_html
|
204 |
)
|
205 |
|
|
|
206 |
with gr.TabItem("๐ Submit Model"):
|
207 |
model_name = gr.Textbox(label="Model Name", placeholder="facebook/wav2vec2-lv-60-espeak-cv-ft")
|
208 |
submission_name = gr.Textbox(label="Submission Name", placeholder="My Model v1.0")
|