Spaces:
Running
Running
Amber Tanaka
commited on
Add redirect script on submit (#115)
Browse files- app.py +37 -1
- content.py +6 -3
- submission.py +1 -1
app.py
CHANGED
|
@@ -102,6 +102,42 @@ const tooltipInterval = setInterval(() => {
|
|
| 102 |
}, 200);
|
| 103 |
</script>
|
| 104 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
# --- Theme Definition ---
|
| 106 |
theme = gr.themes.Base(
|
| 107 |
primary_hue=gr.themes.Color(c100="#CFF5E8", c200="#B7EFDD", c300="#9FEAD1", c400="#87E5C5", c50="#E7FAF3", c500="#6FE0BA", c600="#57DBAF", c700="#3FD5A3", c800="#27D09C", c900="#0FCB8C", c950="#0fcb8c"),
|
|
@@ -197,7 +233,7 @@ final_css = css + f"""
|
|
| 197 |
demo = gr.Blocks(
|
| 198 |
theme=theme,
|
| 199 |
css=final_css,
|
| 200 |
-
head=scroll_script + redirect_script + tooltip_script,
|
| 201 |
title="AstaBench Leaderboards",
|
| 202 |
)
|
| 203 |
with demo.route("Home", "/home"):
|
|
|
|
| 102 |
}, 200);
|
| 103 |
</script>
|
| 104 |
"""
|
| 105 |
+
redirect_submission_on_close_script = """
|
| 106 |
+
<script>
|
| 107 |
+
function initializeRedirectObserver() {
|
| 108 |
+
const successModal = document.querySelector('#success-modal');
|
| 109 |
+
|
| 110 |
+
if (successModal) {
|
| 111 |
+
const observer = new MutationObserver((mutationsList) => {
|
| 112 |
+
for (const mutation of mutationsList) {
|
| 113 |
+
// We only care about changes to the 'class' attribute.
|
| 114 |
+
if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
|
| 115 |
+
|
| 116 |
+
// Check if the 'hide' class has been ADDED to the class list.
|
| 117 |
+
// This is how Gradio hides the modal.
|
| 118 |
+
if (successModal.classList.contains('hide')) {
|
| 119 |
+
console.log("Success modal was closed. Redirecting to homepage...");
|
| 120 |
+
// This is the command to redirect the browser.
|
| 121 |
+
window.location.href = '/home';
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
}
|
| 125 |
+
});
|
| 126 |
+
|
| 127 |
+
// Tell the observer to watch the modal for attribute changes.
|
| 128 |
+
observer.observe(successModal, { attributes: true });
|
| 129 |
+
}
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
// Polling mechanism to wait for Gradio to build the UI.
|
| 133 |
+
const redirectInterval = setInterval(() => {
|
| 134 |
+
if (document.querySelector('#success-modal')) {
|
| 135 |
+
clearInterval(redirectInterval);
|
| 136 |
+
initializeRedirectObserver();
|
| 137 |
+
}
|
| 138 |
+
}, 200);
|
| 139 |
+
</script>
|
| 140 |
+
"""
|
| 141 |
# --- Theme Definition ---
|
| 142 |
theme = gr.themes.Base(
|
| 143 |
primary_hue=gr.themes.Color(c100="#CFF5E8", c200="#B7EFDD", c300="#9FEAD1", c400="#87E5C5", c50="#E7FAF3", c500="#6FE0BA", c600="#57DBAF", c700="#3FD5A3", c800="#27D09C", c900="#0FCB8C", c950="#0fcb8c"),
|
|
|
|
| 233 |
demo = gr.Blocks(
|
| 234 |
theme=theme,
|
| 235 |
css=final_css,
|
| 236 |
+
head=scroll_script + redirect_script + tooltip_script + redirect_submission_on_close_script,
|
| 237 |
title="AstaBench Leaderboards",
|
| 238 |
)
|
| 239 |
with demo.route("Home", "/home"):
|
content.py
CHANGED
|
@@ -579,19 +579,22 @@ span.wrap[tabindex="0"][role="button"][data-editable="false"] {
|
|
| 579 |
max-width: 800px;
|
| 580 |
}
|
| 581 |
/*------ Submission Page CSS ------*/
|
| 582 |
-
#submission-modal .modal-container
|
|
|
|
| 583 |
height: auto;
|
| 584 |
max-width: 600px;
|
| 585 |
}
|
| 586 |
|
| 587 |
-
#submission-modal-content
|
|
|
|
| 588 |
padding: 20px;
|
| 589 |
background-color: inherit;
|
| 590 |
border-radius: 8px;
|
| 591 |
text-align: center;
|
| 592 |
}
|
| 593 |
|
| 594 |
-
#submission-modal-content p
|
|
|
|
| 595 |
font-size: 16px;
|
| 596 |
}
|
| 597 |
|
|
|
|
| 579 |
max-width: 800px;
|
| 580 |
}
|
| 581 |
/*------ Submission Page CSS ------*/
|
| 582 |
+
#submission-modal .modal-container,
|
| 583 |
+
#success-modal .modal-container {
|
| 584 |
height: auto;
|
| 585 |
max-width: 600px;
|
| 586 |
}
|
| 587 |
|
| 588 |
+
#submission-modal-content,
|
| 589 |
+
#success-modal .submission-modal-content {
|
| 590 |
padding: 20px;
|
| 591 |
background-color: inherit;
|
| 592 |
border-radius: 8px;
|
| 593 |
text-align: center;
|
| 594 |
}
|
| 595 |
|
| 596 |
+
#submission-modal-content p,
|
| 597 |
+
#success-modal .submission-modal-content p {
|
| 598 |
font-size: 16px;
|
| 599 |
}
|
| 600 |
|
submission.py
CHANGED
|
@@ -404,7 +404,7 @@ def build_page():
|
|
| 404 |
gr.Markdown("## ⚠️ Error")
|
| 405 |
error_message = gr.Markdown()
|
| 406 |
|
| 407 |
-
with Modal(visible=False, elem_id="
|
| 408 |
with gr.Column(elem_id="submission-modal-content"):
|
| 409 |
gr.Markdown(SUBMISSION_CONFIRMATION)
|
| 410 |
with Modal(visible=False, elem_id="submission-modal") as disclaimer_modal:
|
|
|
|
| 404 |
gr.Markdown("## ⚠️ Error")
|
| 405 |
error_message = gr.Markdown()
|
| 406 |
|
| 407 |
+
with Modal(visible=False, elem_id="success-modal") as success_modal:
|
| 408 |
with gr.Column(elem_id="submission-modal-content"):
|
| 409 |
gr.Markdown(SUBMISSION_CONFIRMATION)
|
| 410 |
with Modal(visible=False, elem_id="submission-modal") as disclaimer_modal:
|