Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
import gradio as gr | |
from utils import submit_gradio_module, load_retrieval_results | |
HEADER = """<div style="text-align: center; margin-bottom: 20px;"> | |
<h1>The Arabic RAG Leaderboard</h1> | |
<p style="font-size: 14px; color: #888;">The only leaderboard you will require for your RAG needs π</p> | |
</div> | |
""" | |
ABOUT_SECTION = """ | |
## About | |
The Arabic RAG Leaderboard is designed to evaluate and compare the performance of Retrieval-Augmented Generation (RAG) models on a set of retrieval and generative tasks. By leveraging a comprehensive evaluation framework, the leaderboard provides a detailed assessment of a model's ability to retrieve relevant information and generate accurate, coherent, and contextually appropriate responses. | |
### Why Focus on RAG Models? | |
The Arabic RAG Leaderboard is specifically designed to assess **RAG models**, which combine retrieval mechanisms with generative capabilities to enhance the quality and relevance of generated content. These models are particularly useful in scenarios where access to up-to-date and contextually relevant information is crucial. While foundational models can be evaluated, the primary focus is on RAG models that excel in both retrieval and generation tasks. | |
### How to Submit Your Model? | |
Navigate to the submission section below to submit your RAG model from the HuggingFace Hub for evaluation. Ensure that your model is public and the submitted metadata (precision, revision, #params) is accurate. | |
### Contact | |
For any inquiries or assistance, feel free to reach out through the community tab at [Navid-AI Community](https://huggingface.co/spaces/Navid-AI/The-Arabic-Rag-Leaderboard/discussions) or via [email](mailto:[email protected]). | |
""" | |
CITATION_BUTTON_LABEL = """ | |
Copy the following snippet to cite these results | |
""" | |
CITATION_BUTTON_TEXT = """ | |
@misc{AraGen, | |
author = {Mohaned A. Rashad, Hamza Shahid}, | |
title = {The Arabic RAG Leaderboard}, | |
year = {2025}, | |
publisher = {Navid-AI}, | |
howpublished = "url{https://huggingface.co/spaces/Navid-AI/The-Arabic-Rag-Leaderboard}" | |
} | |
""" | |
df = load_retrieval_results() | |
print(df) | |
def main(): | |
with gr.Blocks() as demo: | |
gr.HTML(HEADER) | |
with gr.Tabs(): | |
with gr.Tab("Retrieval"): | |
with gr.Tabs(): | |
with gr.Tab("Leaderboard"): | |
with gr.Row(): | |
search_box_retrieval = gr.Textbox( | |
placeholder="Search for models...", | |
label="Search", | |
interactive=True | |
) | |
with gr.Row(): | |
column_selector_tasks = gr.CheckboxGroup( | |
choices=[], | |
value=['Rank', 'Model Name'], | |
label="Select columns to display", | |
) | |
with gr.Row(): | |
license_filter_retrieval = gr.CheckboxGroup( | |
choices=[], | |
value=[], # Default all selected | |
label="Filter by License", | |
) | |
precision_filter_retrieval = gr.CheckboxGroup( | |
choices=[], | |
value=[], # Default all selected | |
label="Filter by Precision", | |
) | |
retrieval_leaderboard = gr.Dataframe( | |
df, | |
interactive=False | |
) | |
# def filter_df_3c3h(search_query, selected_cols, precision_filters, license_filters): | |
# filtered_df = df_3c3h.copy() | |
# # Ensure min_size <= max_size | |
# if min_size > max_size: | |
# min_size, max_size = max_size, min_size | |
# # Apply search filter | |
# if search_query: | |
# filtered_df = filtered_df[filtered_df['Model Name'].str.contains(search_query, case=False, na=False)] | |
# # Apply Precision filter | |
# if precision_filters: | |
# include_missing = 'Missing' in precision_filters | |
# selected_precisions = [p for p in precision_filters if p != 'Missing'] | |
# if include_missing: | |
# filtered_df = filtered_df[ | |
# (filtered_df['Precision'].isin(selected_precisions)) | | |
# (filtered_df['Precision'] == 'UNK') | | |
# (filtered_df['Precision'].isna()) | |
# ] | |
# else: | |
# filtered_df = filtered_df[filtered_df['Precision'].isin(selected_precisions)] | |
# # Apply License filter | |
# if license_filters: | |
# include_missing = 'Missing' in license_filters | |
# selected_licenses = [l for l in license_filters if l != 'Missing'] | |
# if include_missing: | |
# filtered_df = filtered_df[ | |
# (filtered_df['License'].isin(selected_licenses)) | | |
# (filtered_df['License'] == 'UNK') | | |
# (filtered_df['License'].isna()) | |
# ] | |
# else: | |
# filtered_df = filtered_df[filtered_df['License'].isin(selected_licenses)] | |
# # Apply Model Size filter | |
# filtered_df = filtered_df[ | |
# (filtered_df['Model Size Filter'] >= min_size) & | |
# (filtered_df['Model Size Filter'] <= max_size) | |
# ] | |
# # Remove existing 'Rank' column if present | |
# if 'Rank' in filtered_df.columns: | |
# filtered_df = filtered_df.drop(columns=['Rank']) | |
# # Recalculate Rank after filtering | |
# filtered_df = filtered_df.reset_index(drop=True) | |
# filtered_df.insert(0, 'Rank', range(1, len(filtered_df) + 1)) | |
# # Ensure selected columns are present | |
# selected_cols = [col for col in selected_cols if col in filtered_df.columns] | |
# return filtered_df[selected_cols] | |
# # Bind the filter function to the appropriate events | |
# filter_inputs_3c3h = [ | |
# search_box_retrieval, | |
# precision_filter_retrieval, | |
# license_filter_retrieval, | |
# ] | |
# search_box_retrieval.submit( | |
# filter_df_3c3h, | |
# inputs=filter_inputs_3c3h, | |
# outputs=leaderboard_3c3h | |
# ) | |
# # Bind change events for CheckboxGroups and sliders | |
# for component in filter_inputs_3c3h: | |
# component.change( | |
# filter_df_3c3h, | |
# inputs=filter_inputs_3c3h, | |
# outputs=leaderboard_3c3h | |
# ) | |
submit_gradio_module() | |
with gr.Tab("Reranking"): | |
with gr.Tabs(): | |
with gr.Tab("Leaderboard"): | |
with gr.Row(): | |
search_box_tasks = gr.Textbox( | |
placeholder="Search for models...", | |
label="Search", | |
interactive=True | |
) | |
with gr.Row(): | |
column_selector_tasks = gr.CheckboxGroup( | |
choices=[], | |
value=['Rank', 'Model Name'], | |
label="Select columns to display", | |
) | |
with gr.Row(): | |
license_filter_tasks = gr.CheckboxGroup( | |
choices=[], | |
value=[], # Default all selected | |
label="Filter by License", | |
) | |
precision_filter_tasks = gr.CheckboxGroup( | |
choices=[], | |
value=[], # Default all selected | |
label="Filter by Precision", | |
) | |
# with gr.Row(): | |
# model_size_min_filter_tasks = gr.Slider( | |
# minimum=min_model_size_tasks, | |
# maximum=max_model_size_tasks, | |
# value=min_model_size_tasks, | |
# step=1, | |
# label="Minimum Model Size", | |
# interactive=True | |
# ) | |
# model_size_max_filter_tasks = gr.Slider( | |
# minimum=min_model_size_tasks, | |
# maximum=max_model_size_tasks, | |
# value=max_model_size_tasks, | |
# step=1, | |
# label="Maximum Model Size", | |
# interactive=True | |
# ) | |
leaderboard_tasks = gr.Dataframe( | |
df, | |
# headers="auto", # Automatically use DataFrame's headers | |
# label="MultiIndex DataFrame", | |
# interactive=False, | |
) | |
# def filter_df_tasks(search_query, selected_cols, precision_filters, license_filters, min_size, max_size): | |
# filtered_df = df_tasks.copy() | |
# # Ensure min_size <= max_size | |
# if min_size > max_size: | |
# min_size, max_size = max_size, min_size | |
# # Apply search filter | |
# if search_query: | |
# filtered_df = filtered_df[filtered_df['Model Name'].str.contains(search_query, case=False, na=False)] | |
# # Apply Precision filter | |
# if precision_filters: | |
# include_missing = 'Missing' in precision_filters | |
# selected_precisions = [p for p in precision_filters if p != 'Missing'] | |
# if include_missing: | |
# filtered_df = filtered_df[ | |
# (filtered_df['Precision'].isin(selected_precisions)) | | |
# (filtered_df['Precision'] == 'UNK') | | |
# (filtered_df['Precision'].isna()) | |
# ] | |
# else: | |
# filtered_df = filtered_df[filtered_df['Precision'].isin(selected_precisions)] | |
# # Apply License filter | |
# if license_filters: | |
# include_missing = 'Missing' in license_filters | |
# selected_licenses = [l for l in license_filters if l != 'Missing'] | |
# if include_missing: | |
# filtered_df = filtered_df[ | |
# (filtered_df['License'].isin(selected_licenses)) | | |
# (filtered_df['License'] == 'UNK') | | |
# (filtered_df['License'].isna()) | |
# ] | |
# else: | |
# filtered_df = filtered_df[filtered_df['License'].isin(selected_licenses)] | |
# # Apply Model Size filter | |
# filtered_df = filtered_df[ | |
# (filtered_df['Model Size Filter'] >= min_size) & | |
# (filtered_df['Model Size Filter'] <= max_size) | |
# ] | |
# # Remove existing 'Rank' column if present | |
# if 'Rank' in filtered_df.columns: | |
# filtered_df = filtered_df.drop(columns=['Rank']) | |
# # Sort by the first task column if it exists | |
# if task_columns: | |
# first_task = task_columns[0] | |
# filtered_df = filtered_df.sort_values(by=first_task, ascending=False) | |
# else: | |
# filtered_df = filtered_df.sort_values(by='Model Name', ascending=True) | |
# # Recalculate Rank after filtering | |
# filtered_df = filtered_df.reset_index(drop=True) | |
# filtered_df.insert(0, 'Rank', range(1, len(filtered_df) + 1)) | |
# # Ensure selected columns are present | |
# selected_cols = [col for col in selected_cols if col in filtered_df.columns] | |
# return filtered_df[selected_cols] | |
# # Bind the filter function to the appropriate events | |
# filter_inputs_tasks = [ | |
# search_box_tasks, | |
# column_selector_tasks, | |
# precision_filter_tasks, | |
# license_filter_tasks, | |
# model_size_min_filter_tasks, | |
# model_size_max_filter_tasks | |
# ] | |
# search_box_tasks.submit( | |
# filter_df_tasks, | |
# inputs=filter_inputs_tasks, | |
# outputs=leaderboard_tasks | |
# ) | |
# # Bind change events for CheckboxGroups and sliders | |
# for component in filter_inputs_tasks: | |
# component.change( | |
# filter_df_tasks, | |
# inputs=filter_inputs_tasks, | |
# outputs=leaderboard_tasks | |
# ) | |
submit_gradio_module() | |
with gr.Tab("LLM Context Answering"): | |
with gr.Tabs(): | |
with gr.Tab("Leaderboard"): | |
pass | |
with gr.Tab("Submit Here"): | |
pass | |
with gr.Row(): | |
with gr.Accordion("π Citation", open=False): | |
gr.Textbox( | |
value=CITATION_BUTTON_TEXT, | |
label=CITATION_BUTTON_LABEL, | |
lines=20, | |
elem_id="citation-button", | |
show_copy_button=True, | |
) | |
demo.launch() | |
if __name__ == "__main__": | |
main() | |