David Pomerenke
commited on
Commit
·
9f25f4c
1
Parent(s):
d3bce4d
Hack to make search links work
Browse files
app.py
CHANGED
@@ -610,36 +610,52 @@ css="""
|
|
610 |
|
611 |
shortcut_js = """
|
612 |
<script>
|
|
|
613 |
const params = new URLSearchParams(window.location.search);
|
614 |
const lang = params.get("lang");
|
615 |
-
|
616 |
if (lang) {
|
617 |
-
console.log("redirecting to " + lang);
|
618 |
window.location.href = "/" + lang;
|
619 |
}
|
|
|
|
|
620 |
const copyLinkToClipboard = (link) => {
|
621 |
navigator.clipboard.writeText(link);
|
622 |
console.log("Copied link to clipboard: " + link);
|
623 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
624 |
</script>
|
625 |
"""
|
626 |
|
627 |
|
628 |
# Create the visualization components
|
629 |
with gr.Blocks(title="AI Language Proficiency Benchmark", css=css, head=shortcut_js) as demo:
|
630 |
-
gr.Markdown("# AI Language Proficiency Benchmark")
|
631 |
-
gr.Markdown("Comparing language proficiency across different models and languages.")
|
632 |
-
|
633 |
language_choices = [
|
634 |
f"{lang['language_name']} ({lang['bcp_47']})" for lang in languages
|
635 |
]
|
636 |
models = {score["model"] for lang in languages for score in lang["scores"]}
|
637 |
search = gr.Dropdown(
|
638 |
-
choices=list(models)
|
639 |
-
value=
|
640 |
-
|
641 |
interactive=True,
|
|
|
|
|
642 |
)
|
|
|
|
|
|
|
|
|
643 |
with gr.Row():
|
644 |
start_model_type = "Text-to-Text"
|
645 |
model_type = gr.Radio(
|
|
|
610 |
|
611 |
shortcut_js = """
|
612 |
<script>
|
613 |
+
// Handle URL parameters for direct language access
|
614 |
const params = new URLSearchParams(window.location.search);
|
615 |
const lang = params.get("lang");
|
616 |
+
|
617 |
if (lang) {
|
|
|
618 |
window.location.href = "/" + lang;
|
619 |
}
|
620 |
+
|
621 |
+
// Function to copy link to clipboard
|
622 |
const copyLinkToClipboard = (link) => {
|
623 |
navigator.clipboard.writeText(link);
|
624 |
console.log("Copied link to clipboard: " + link);
|
625 |
}
|
626 |
+
|
627 |
+
const redirect_to_lang = lang_descriptor => {
|
628 |
+
lang_code = lang_descriptor.split("(")[1].split(")")[0];
|
629 |
+
console.log("redirecting to /" + lang_code);
|
630 |
+
window.location.href = "/" + lang_code;
|
631 |
+
}
|
632 |
+
|
633 |
+
const empty_search = () => {
|
634 |
+
console.log("empty search");
|
635 |
+
document.getElementById("search-dropdown").value = "";
|
636 |
+
}
|
637 |
</script>
|
638 |
"""
|
639 |
|
640 |
|
641 |
# Create the visualization components
|
642 |
with gr.Blocks(title="AI Language Proficiency Benchmark", css=css, head=shortcut_js) as demo:
|
|
|
|
|
|
|
643 |
language_choices = [
|
644 |
f"{lang['language_name']} ({lang['bcp_47']})" for lang in languages
|
645 |
]
|
646 |
models = {score["model"] for lang in languages for score in lang["scores"]}
|
647 |
search = gr.Dropdown(
|
648 |
+
choices=language_choices, # + list(models),
|
649 |
+
value="Search for Language or Model",
|
650 |
+
allow_custom_value=True,
|
651 |
interactive=True,
|
652 |
+
container=False,
|
653 |
+
elem_id="search-dropdown"
|
654 |
)
|
655 |
+
search.focus(fn=lambda x: None, inputs=search, outputs=None, js="(x) => {empty_search()}")
|
656 |
+
search.change(fn=lambda x: None, inputs=search, outputs=None, js="(x) => {redirect_to_lang(x)}")
|
657 |
+
gr.Markdown("# AI Language Proficiency Benchmark")
|
658 |
+
gr.Markdown("Comparing language proficiency across different models and languages.")
|
659 |
with gr.Row():
|
660 |
start_model_type = "Text-to-Text"
|
661 |
model_type = gr.Radio(
|