|  | import pandas as pd | 
					
						
						|  |  | 
					
						
						|  | import gradio as gr | 
					
						
						|  | from gradio_leaderboard import Leaderboard | 
					
						
						|  |  | 
					
						
						|  | from utils import fetch_hf_results, show_output_box | 
					
						
						|  | from constants import ( | 
					
						
						|  | ASSAY_LIST, | 
					
						
						|  | ASSAY_RENAME, | 
					
						
						|  | ASSAY_EMOJIS, | 
					
						
						|  | ASSAY_DESCRIPTION, | 
					
						
						|  | EXAMPLE_FILE_DICT, | 
					
						
						|  | LEADERBOARD_DISPLAY_COLUMNS, | 
					
						
						|  | ) | 
					
						
						|  | from about import ABOUT_INTRO, ABOUT_TEXT, FAQS | 
					
						
						|  | from submit import make_submission | 
					
						
						|  |  | 
					
						
						|  | def format_leaderboard_table(df_results: pd.DataFrame, assay: str | None = None): | 
					
						
						|  | df = df_results.query("assay.isin(@ASSAY_RENAME.keys())").copy() | 
					
						
						|  | if assay is not None: | 
					
						
						|  | df = df[df["assay"] == assay] | 
					
						
						|  | df = df[LEADERBOARD_DISPLAY_COLUMNS] | 
					
						
						|  | df = df.sort_values(by="spearman", ascending=False) | 
					
						
						|  |  | 
					
						
						|  |  | 
					
						
						|  |  | 
					
						
						|  | df["spearman"] = df["spearman"].astype(str) | 
					
						
						|  | df.loc[(df["dataset"] == "Heldout Test Set") & (df["spearman"] == "nan"), "spearman"] = "N/A, evaluated at competition close" | 
					
						
						|  | return df | 
					
						
						|  |  | 
					
						
						|  |  | 
					
						
						|  | def get_leaderboard_object(assay: str | None = None): | 
					
						
						|  | filter_columns = ["dataset"] | 
					
						
						|  | if assay is None: | 
					
						
						|  | filter_columns.append("property") | 
					
						
						|  |  | 
					
						
						|  |  | 
					
						
						|  |  | 
					
						
						|  | lb = Leaderboard( | 
					
						
						|  | value=format_leaderboard_table(df_results=current_dataframe, assay=assay), | 
					
						
						|  | datatype=["str", "str", "str", "number"], | 
					
						
						|  | select_columns=["model", "property", "spearman", "dataset"], | 
					
						
						|  | search_columns=["model"], | 
					
						
						|  | filter_columns=filter_columns, | 
					
						
						|  | every=15, | 
					
						
						|  | render=True, | 
					
						
						|  | ) | 
					
						
						|  | return lb | 
					
						
						|  |  | 
					
						
						|  |  | 
					
						
						|  |  | 
					
						
						|  | current_dataframe = fetch_hf_results() | 
					
						
						|  |  | 
					
						
						|  | with gr.Blocks() as demo: | 
					
						
						|  | timer = gr.Timer(3) | 
					
						
						|  | data_version = gr.State(value=0) | 
					
						
						|  |  | 
					
						
						|  | def update_current_dataframe(): | 
					
						
						|  | global current_dataframe | 
					
						
						|  | new_dataframe = fetch_hf_results() | 
					
						
						|  |  | 
					
						
						|  |  | 
					
						
						|  | if not current_dataframe.equals(new_dataframe): | 
					
						
						|  | current_dataframe = new_dataframe | 
					
						
						|  | return data_version.value + 1 | 
					
						
						|  | return data_version.value | 
					
						
						|  |  | 
					
						
						|  | timer.tick(fn=update_current_dataframe, outputs=data_version) | 
					
						
						|  |  | 
					
						
						|  |  | 
					
						
						|  | gr.Markdown(""" | 
					
						
						|  | ## Welcome to the Ginkgo Antibody Developability Benchmark! | 
					
						
						|  |  | 
					
						
						|  | **Beta version, not publicly launched yet** | 
					
						
						|  |  | 
					
						
						|  | Participants can submit their model to the leaderboard by uploading a CSV file (see the "✉️ Submit" tab). | 
					
						
						|  | See more details in the "❔About" tab. | 
					
						
						|  | """) | 
					
						
						|  | with gr.Tabs(elem_classes="tab-buttons"): | 
					
						
						|  | with gr.TabItem("❔About", elem_id="abdev-benchmark-tab-table"): | 
					
						
						|  | gr.Image( | 
					
						
						|  | value="./assets/competition_logo.jpg", | 
					
						
						|  | show_label=False, | 
					
						
						|  |  | 
					
						
						|  | show_download_button=False, | 
					
						
						|  | width="50vw", | 
					
						
						|  | ) | 
					
						
						|  | gr.Markdown(ABOUT_INTRO) | 
					
						
						|  | gr.Image(value="./assets/prediction_explainer.png", show_label=False, show_download_button=False, width="50vw") | 
					
						
						|  | gr.Markdown(ABOUT_TEXT) | 
					
						
						|  | gr.Markdown("### FAQs") | 
					
						
						|  | for i, (question, answer) in enumerate(FAQS.items()): | 
					
						
						|  |  | 
					
						
						|  | question = f"{i+1}. {question}" | 
					
						
						|  | with gr.Accordion(question, open=False): | 
					
						
						|  | gr.Markdown(f"*{answer}*") | 
					
						
						|  |  | 
					
						
						|  |  | 
					
						
						|  | for i, assay in enumerate(ASSAY_LIST): | 
					
						
						|  | with gr.TabItem( | 
					
						
						|  | f"{ASSAY_EMOJIS[assay]} {ASSAY_RENAME[assay]}", | 
					
						
						|  | elem_id="abdev-benchmark-tab-table", | 
					
						
						|  | ) as tab_item: | 
					
						
						|  | gr.Markdown(f"# {ASSAY_DESCRIPTION[assay]}") | 
					
						
						|  | lb = get_leaderboard_object(assay=assay) | 
					
						
						|  |  | 
					
						
						|  | def refresh_leaderboard(assay=assay): | 
					
						
						|  | return format_leaderboard_table(df_results=current_dataframe, assay=assay) | 
					
						
						|  |  | 
					
						
						|  |  | 
					
						
						|  | data_version.change(fn=refresh_leaderboard, outputs=lb) | 
					
						
						|  |  | 
					
						
						|  | with gr.TabItem("🚀 Overall", elem_id="abdev-benchmark-tab-table") as overall_tab: | 
					
						
						|  | gr.Markdown( | 
					
						
						|  | "# Antibody Developability Benchmark Leaderboard over all properties" | 
					
						
						|  | ) | 
					
						
						|  | lb = get_leaderboard_object() | 
					
						
						|  |  | 
					
						
						|  | def refresh_overall_leaderboard(): | 
					
						
						|  | return format_leaderboard_table(df_results=current_dataframe) | 
					
						
						|  |  | 
					
						
						|  |  | 
					
						
						|  | data_version.change(fn=refresh_overall_leaderboard, outputs=lb) | 
					
						
						|  |  | 
					
						
						|  | with gr.TabItem("✉️ Submit", elem_id="boundary-benchmark-tab-table"): | 
					
						
						|  | gr.Markdown( | 
					
						
						|  | f""" | 
					
						
						|  | # Antibody Developability Submission | 
					
						
						|  | Upload a CSV to get a score! | 
					
						
						|  | List of valid property names: `{', '.join(ASSAY_LIST)}`. | 
					
						
						|  |  | 
					
						
						|  | Please use your Hugging Face account name to submit your model - we use this to track separate submissions, and if you would like to remain anonymous please set up an anonymous huggingface account. | 
					
						
						|  | Your submission will be evaluated and added to the leaderboard. | 
					
						
						|  | """ | 
					
						
						|  | ) | 
					
						
						|  | submission_type_state = gr.State(value="GDPa1") | 
					
						
						|  | download_file_state = gr.State(value=EXAMPLE_FILE_DICT["GDPa1"]) | 
					
						
						|  |  | 
					
						
						|  | with gr.Row(): | 
					
						
						|  | with gr.Column(): | 
					
						
						|  | username_input = gr.Textbox( | 
					
						
						|  | label="Username", | 
					
						
						|  | placeholder="Enter your Hugging Face username", | 
					
						
						|  | info="This will be used to track your submissions, and to update your results if you submit again.", | 
					
						
						|  | ) | 
					
						
						|  | model_name_input = gr.Textbox( | 
					
						
						|  | label="Model Name", | 
					
						
						|  | placeholder="Enter your model name (e.g., 'MyProteinLM-v1')", | 
					
						
						|  | info="This will be displayed on the leaderboard.", | 
					
						
						|  | ) | 
					
						
						|  | model_description_input = gr.Textbox( | 
					
						
						|  | label="Model Description (optional)", | 
					
						
						|  | placeholder="Brief description of your model and approach", | 
					
						
						|  | info="Describe your model, training data, or methodology.", | 
					
						
						|  | lines=3, | 
					
						
						|  | ) | 
					
						
						|  | anonymous_checkbox = gr.Checkbox( | 
					
						
						|  | label="Anonymous", | 
					
						
						|  | value=False, | 
					
						
						|  | info="If checked, your username will be replaced with an anonymous username on the leaderboard.", | 
					
						
						|  | ) | 
					
						
						|  | registration_code = gr.Textbox( | 
					
						
						|  | label="Registration Code", | 
					
						
						|  | placeholder="Enter your registration code", | 
					
						
						|  | info="If you did not receive a registration code, please sign up on the <a href='https://datapoints.ginkgo.bio/ai-competitions/2025-abdev-competition'>Competition Registration page</a> or email <a href='mailto:[email protected]'>[email protected]</a>.", | 
					
						
						|  | ) | 
					
						
						|  | with gr.Column(): | 
					
						
						|  | submission_type_dropdown = gr.Dropdown( | 
					
						
						|  | choices=["GDPa1", "GDPa1_cross_validation", "Heldout Test Set"], | 
					
						
						|  | value="GDPa1", | 
					
						
						|  | label="Submission Type", | 
					
						
						|  | ) | 
					
						
						|  | download_button = gr.DownloadButton( | 
					
						
						|  | label="📥 Download example submission CSV for GDPa1", | 
					
						
						|  | value=EXAMPLE_FILE_DICT["GDPa1"], | 
					
						
						|  | variant="secondary", | 
					
						
						|  | ) | 
					
						
						|  | submission_file = gr.File(label="Submission CSV") | 
					
						
						|  |  | 
					
						
						|  | def update_submission_type_and_file(submission_type): | 
					
						
						|  | """ | 
					
						
						|  | Based on the submission type selected in the dropdown, | 
					
						
						|  | Update the submission type state | 
					
						
						|  | Dynamically update example file for download | 
					
						
						|  | """ | 
					
						
						|  | download_file = EXAMPLE_FILE_DICT.get( | 
					
						
						|  | submission_type, EXAMPLE_FILE_DICT[submission_type] | 
					
						
						|  | ) | 
					
						
						|  | download_label = ( | 
					
						
						|  | f"📥 Download example submission CSV for {submission_type}" | 
					
						
						|  | ) | 
					
						
						|  | return ( | 
					
						
						|  | submission_type, | 
					
						
						|  | download_file, | 
					
						
						|  | gr.DownloadButton( | 
					
						
						|  | label=download_label, | 
					
						
						|  | value=download_file, | 
					
						
						|  | variant="secondary", | 
					
						
						|  | ), | 
					
						
						|  | ) | 
					
						
						|  |  | 
					
						
						|  |  | 
					
						
						|  | submission_type_dropdown.change( | 
					
						
						|  | fn=update_submission_type_and_file, | 
					
						
						|  | inputs=submission_type_dropdown, | 
					
						
						|  | outputs=[submission_type_state, download_file_state, download_button], | 
					
						
						|  | ) | 
					
						
						|  |  | 
					
						
						|  | submit_btn = gr.Button("Evaluate") | 
					
						
						|  | message = gr.Textbox(label="Status", lines=1, visible=False) | 
					
						
						|  |  | 
					
						
						|  | gr.Markdown( | 
					
						
						|  | "If you have issues with submission or using the leaderboard, please start a discussion in the Community tab of this Space." | 
					
						
						|  | ) | 
					
						
						|  |  | 
					
						
						|  | submit_btn.click( | 
					
						
						|  | make_submission, | 
					
						
						|  | inputs=[ | 
					
						
						|  | submission_file, | 
					
						
						|  | username_input, | 
					
						
						|  | submission_type_state, | 
					
						
						|  | model_name_input, | 
					
						
						|  | model_description_input, | 
					
						
						|  | anonymous_checkbox, | 
					
						
						|  | registration_code, | 
					
						
						|  | ], | 
					
						
						|  | outputs=[message], | 
					
						
						|  | ).then( | 
					
						
						|  | fn=show_output_box, | 
					
						
						|  | inputs=[message], | 
					
						
						|  | outputs=[message], | 
					
						
						|  | ) | 
					
						
						|  |  | 
					
						
						|  | gr.Markdown( | 
					
						
						|  | """ | 
					
						
						|  | <div style="text-align: center; font-size: 14px; color: gray; margin-top: 2em;"> | 
					
						
						|  | 📬 For questions or feedback, contact <a href="mailto:[email protected]">[email protected]</a> or visit the Community tab at the top of this page.<br> | 
					
						
						|  | Visit the <a href="https://datapoints.ginkgo.bio/ai-competitions/2025-abdev-competition">Competition Registration page</a> to sign up for updates and to register a team. | 
					
						
						|  | </div> | 
					
						
						|  | """, | 
					
						
						|  | elem_id="contact-footer", | 
					
						
						|  | ) | 
					
						
						|  |  | 
					
						
						|  | if __name__ == "__main__": | 
					
						
						|  | demo.launch(ssr_mode=False) | 
					
						
						|  |  |