Spaces:
Running
Running
Amber Tanaka
commited on
make button work better (#36)
Browse files- app.py +6 -10
- content.py +5 -0
- ui_components.py +9 -18
app.py
CHANGED
|
@@ -23,7 +23,7 @@ PROJECT_NAME = "asta-bench" + ("-internal" if IS_INTERNAL else "")
|
|
| 23 |
LEADERBOARD_PATH = f"{OWNER}/{PROJECT_NAME}-leaderboard"
|
| 24 |
api = HfApi()
|
| 25 |
LOGO_PATH = "assets/logo.svg"
|
| 26 |
-
#
|
| 27 |
scroll_script = """
|
| 28 |
<script>
|
| 29 |
function scroll_to_element(id) {
|
|
@@ -38,8 +38,11 @@ function scroll_to_element(id) {
|
|
| 38 |
}
|
| 39 |
</script>
|
| 40 |
"""
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
# --- Theme Definition ---
|
| 45 |
theme = gr.themes.Base(
|
|
@@ -97,13 +100,6 @@ except FileNotFoundError:
|
|
| 97 |
print(f"Warning: Home icon file not found at {LOGO_PATH}.")
|
| 98 |
home_icon_data_uri = "none"
|
| 99 |
|
| 100 |
-
# --- This part creates the JavaScript redirect. It is correct. ---
|
| 101 |
-
redirect_script = """
|
| 102 |
-
<script>
|
| 103 |
-
if (window.location.pathname === '/') { window.location.replace('/home'); }
|
| 104 |
-
</script>
|
| 105 |
-
"""
|
| 106 |
-
|
| 107 |
# --- This is the final CSS ---
|
| 108 |
final_css = css + f"""
|
| 109 |
/* --- Find the "Home" button and replace its text with an icon --- */
|
|
|
|
| 23 |
LEADERBOARD_PATH = f"{OWNER}/{PROJECT_NAME}-leaderboard"
|
| 24 |
api = HfApi()
|
| 25 |
LOGO_PATH = "assets/logo.svg"
|
| 26 |
+
# JavaScripts
|
| 27 |
scroll_script = """
|
| 28 |
<script>
|
| 29 |
function scroll_to_element(id) {
|
|
|
|
| 38 |
}
|
| 39 |
</script>
|
| 40 |
"""
|
| 41 |
+
redirect_script = """
|
| 42 |
+
<script>
|
| 43 |
+
if (window.location.pathname === '/') { window.location.replace('/home'); }
|
| 44 |
+
</script>
|
| 45 |
+
"""
|
| 46 |
|
| 47 |
# --- Theme Definition ---
|
| 48 |
theme = gr.themes.Base(
|
|
|
|
| 100 |
print(f"Warning: Home icon file not found at {LOGO_PATH}.")
|
| 101 |
home_icon_data_uri = "none"
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
# --- This is the final CSS ---
|
| 104 |
final_css = css + f"""
|
| 105 |
/* --- Find the "Home" button and replace its text with an icon --- */
|
content.py
CHANGED
|
@@ -411,6 +411,11 @@ span.wrap[tabindex="0"][role="button"][data-editable="false"] {
|
|
| 411 |
display: flex !important;
|
| 412 |
align-items: center !important;
|
| 413 |
gap: 20px !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 414 |
}
|
| 415 |
.scroll-up-button {
|
| 416 |
flex-grow: 0;
|
|
|
|
| 411 |
display: flex !important;
|
| 412 |
align-items: center !important;
|
| 413 |
gap: 20px !important;
|
| 414 |
+
width: 100% !important;
|
| 415 |
+
}
|
| 416 |
+
.scroll-up-container .prose {
|
| 417 |
+
display: flex;
|
| 418 |
+
justify-content: flex-end;
|
| 419 |
}
|
| 420 |
.scroll-up-button {
|
| 421 |
flex-grow: 0;
|
ui_components.py
CHANGED
|
@@ -379,28 +379,19 @@ def create_benchmark_details_display(
|
|
| 379 |
|
| 380 |
gr.Markdown("---")
|
| 381 |
gr.Markdown("## Detailed Benchmark Results")
|
| 382 |
-
scroll_to_top_js = """
|
| 383 |
-
() => {
|
| 384 |
-
console.log("Scroll button clicked. Checking for HF iframe environment...");
|
| 385 |
-
if ('parentIFrame' in window) {
|
| 386 |
-
console.log("HF iframe detected. Using window.parentIFrame.scrollTo().");
|
| 387 |
-
window.parentIFrame.scrollTo({top: 0, behavior: 'smooth'});
|
| 388 |
-
} else {
|
| 389 |
-
console.log("No HF iframe detected. Using standard window.scrollTo().");
|
| 390 |
-
window.scrollTo({top: 0, behavior: 'smooth'});
|
| 391 |
-
}
|
| 392 |
-
}
|
| 393 |
-
"""
|
| 394 |
# 2. Loop through each benchmark and create its UI components
|
| 395 |
for benchmark_name in benchmark_names:
|
| 396 |
with gr.Row(elem_classes=["benchmark-header"]):
|
| 397 |
gr.Markdown(f"### {benchmark_name} Leaderboard", header_links=True)
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
|
|
|
|
|
|
|
|
|
| 404 |
|
| 405 |
# 3. Prepare the data for this specific benchmark's table and plot
|
| 406 |
benchmark_score_col = f"{benchmark_name} Score"
|
|
|
|
| 379 |
|
| 380 |
gr.Markdown("---")
|
| 381 |
gr.Markdown("## Detailed Benchmark Results")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 382 |
# 2. Loop through each benchmark and create its UI components
|
| 383 |
for benchmark_name in benchmark_names:
|
| 384 |
with gr.Row(elem_classes=["benchmark-header"]):
|
| 385 |
gr.Markdown(f"### {benchmark_name} Leaderboard", header_links=True)
|
| 386 |
+
button_str = f"""
|
| 387 |
+
<button
|
| 388 |
+
class="scroll-up-button"
|
| 389 |
+
onclick="scroll_to_element('page-content-wrapper')"
|
| 390 |
+
>
|
| 391 |
+
{"⬆"}
|
| 392 |
+
</button>
|
| 393 |
+
"""
|
| 394 |
+
gr.HTML(button_str,elem_classes="scroll-up-container")
|
| 395 |
|
| 396 |
# 3. Prepare the data for this specific benchmark's table and plot
|
| 397 |
benchmark_score_col = f"{benchmark_name} Score"
|