Mezura / app.py
nmmursit's picture
feat: Add structured output support and refactor comments
7dea7c1
import gradio as gr
import pandas as pd
import os
import sys
import traceback
import logging
from datetime import datetime, timezone
from pathlib import Path
# Disable SSL verification for curl requests if needed
os.environ['CURL_CA_BUNDLE'] = ''
# Configure minimal logging first thing - before any imports
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logging.getLogger("httpx").setLevel(logging.ERROR)
logging.getLogger("urllib3").setLevel(logging.ERROR)
logging.getLogger("matplotlib").setLevel(logging.WARNING)
logging.getLogger("huggingface_hub").setLevel(logging.ERROR)
from gradio.oauth import OAuthProfile
from src.display.about import (
CITATION_BUTTON_LABEL,
CITATION_BUTTON_TEXT,
EVALUATION_QUEUE_TEXT,
INTRODUCTION_TEXT,
LLM_BENCHMARKS_TEXT,
TITLE,
)
from src.display.css_html_js import custom_css
from src.utils import (
restart_space,
load_benchmark_results,
create_benchmark_plots,
create_combined_leaderboard_table,
create_evalmix_table,
create_light_eval_table,
create_raw_details_table,
create_human_arena_table,
create_structured_outputs_table,
update_supported_base_models
)
from pipelines.utils.common import search_and_filter
from pipelines.unified_benchmark import submit_unified_benchmark
# Evaluation types
EVAL_TYPES = ["EvalMix", "RAG-Judge", "Light-Eval", "Arena", "Snake-Bench"]
# Initialize OAuth configuration
OAUTH_CLIENT_ID = os.getenv("OAUTH_CLIENT_ID")
OAUTH_CLIENT_SECRET = os.getenv("OAUTH_CLIENT_SECRET")
OAUTH_SCOPES = os.getenv("OAUTH_SCOPES", "email")
OPENID_PROVIDER_URL = os.getenv("OPENID_PROVIDER_URL")
SESSION_TIMEOUT_MINUTES = int(os.getenv("HF_OAUTH_EXPIRATION_MINUTES", 30))
def format_dataframe(df, is_light_eval_detail=False):
"""
Float değerleri 2 ondalık basamağa yuvarla,
'file' sütununu kaldır ve kolon isimlerini düzgün formata getir
Args:
df: DataFrame to format
is_light_eval_detail: If True, use 4 decimal places for light eval detail results
"""
if df.empty:
return df
if 'file' in df.columns:
df = df.drop(columns=['file'])
# Specifically remove problematic columns
columns_to_remove = ["run_id", "user_id", "total_success_references", "Total Success References", "total_eval_samples",
"total_samples", "samples_number"]
for col in columns_to_remove:
if col in df.columns:
df = df.drop(columns=[col])
# Float değerleri yuvarlama
# Varsayılan: 2 hane. Light eval detail veya structured_output_score kolonları varsa: 4 hane.
# Leaderboard için özel durum: "Structured Outputs" ve "Retrieval" kolonlarını 4 hane tut.
if is_light_eval_detail or "structured_output_score" in df.columns:
default_decimal_places = 4
else:
default_decimal_places = 2
four_decimal_cols = {"Structured Outputs"}
for column in df.columns:
try:
if pd.api.types.is_float_dtype(df[column]):
if column in four_decimal_cols:
df[column] = df[column].round(4)
else:
df[column] = df[column].round(default_decimal_places)
except:
continue
column_mapping = {}
for col in df.columns:
# Skip run_id and user_id fields
if col.lower() in ["run_id", "user_id"]:
continue
# Special handling for Turkish Semantic column
if "turkish_semantic" in col.lower():
column_mapping[col] = "Turkish Semantic"
continue
# Special handling for Multilingual Semantic column
if "multilingual_semantic" in col.lower():
column_mapping[col] = "Multilingual Semantic"
continue
# Skip already well-formatted columns or columns that contain special characters
if col == "Model Name" or " " in col:
# Still process column if it contains "mean"
if " mean" in col.lower():
cleaned_col = col.replace(" mean", "").replace(" Mean", "")
column_mapping[col] = cleaned_col
continue
# model_name column should be Model Name
if col == "model_name":
column_mapping[col] = "Model Name"
continue
# Remove the word "mean" from column names (case insensitive)
cleaned_col = col.replace(" mean", "").replace("_mean", "")
# Format column name by replacing underscores with spaces and capitalizing each word
formatted_col = " ".join([word.capitalize() for word in cleaned_col.replace("_", " ").split()])
column_mapping[col] = formatted_col
# Rename columns with the mapping
if column_mapping:
df = df.rename(columns=column_mapping)
return df
# User authentication function
def check_user_login(profile):
if profile is None:
return False, "Please log in with your Hugging Face account to submit models for benchmarking."
# In some environments, profile may be a string instead of a profile object
if isinstance(profile, str):
if profile == "":
return False, "Please log in with your Hugging Face account to submit models for benchmarking."
return True, f"Logged in as {profile}"
# Normal case where profile is an object with username attribute
return True, f"Logged in as {profile.username}"
def create_demo():
# Get logger for this function
logger = logging.getLogger("mezura")
with gr.Blocks(css=custom_css) as demo:
# Update supported base models at startup
logger.info("Updating supported base models at startup...")
update_supported_base_models()
logger.info("Base models updated successfully")
gr.Markdown(TITLE)
gr.Markdown(INTRODUCTION_TEXT)
session_expiry = gr.State(None)
try:
benchmark_results = load_benchmark_results()
default_plots = create_benchmark_plots(benchmark_results, "avg")
login_state = gr.State(value=False)
with gr.Tabs() as tabs:
with gr.TabItem("🏆 LLM Benchmark", elem_id="llm-benchmark-tab"):
gr.Markdown("## Model Evaluation Results")
gr.Markdown("This screen shows model performance across different evaluation categories.")
with gr.Row():
search_input = gr.Textbox(
label="🔍 Search for your model (separate multiple queries with `;`) and press ENTER...",
placeholder="Enter model name or evaluation information...",
show_label=False
)
# # Update refresh button to be orange with "Refresh Results" text
# refresh_button = gr.Button("🔄 Refresh Results", variant="primary")
# # Status display for refresh results
# refresh_status = gr.Markdown("", visible=False)
with gr.Tabs() as benchmark_tabs:
with gr.TabItem("👥 Human Arena"):
human_arena_data = benchmark_results["raw"]["human_arena"]
# Store human arena data in a state component for filtering
human_arena_state = gr.State(value=human_arena_data)
# Store active category state
active_category_state = gr.State(value="general")
# Category filter buttons
with gr.Row():
general_btn = gr.Button("General", variant="primary", elem_id="human_arena_general_btn", elem_classes=["active-btn"])
reasoning_btn = gr.Button("Reasoning", variant="secondary", elem_id="human_arena_reasoning_btn")
# Function to filter and update table, and update button states
def filter_human_arena_table(category, data):
if not data:
filtered_df = pd.DataFrame({"Model Name": ["No data available"]})
else:
filtered_df = create_human_arena_table(data, category=category)
filtered_df = format_dataframe(filtered_df)
if filtered_df.empty:
filtered_df = pd.DataFrame({"Model Name": ["No data available"]})
if category == "general":
return (
filtered_df,
category,
gr.Button("General", variant="primary", elem_id="human_arena_general_btn", elem_classes=["active-btn"]),
gr.Button("Reasoning", variant="secondary", elem_id="human_arena_reasoning_btn")
)
else:
return (
filtered_df,
category,
gr.Button("General", variant="secondary", elem_id="human_arena_general_btn"),
gr.Button("Reasoning", variant="primary", elem_id="human_arena_reasoning_btn", elem_classes=["active-btn"])
)
if human_arena_data:
human_arena_df = create_human_arena_table(human_arena_data, category="general")
else:
human_arena_df = pd.DataFrame()
human_arena_df = format_dataframe(human_arena_df)
if human_arena_df.empty:
human_arena_df = pd.DataFrame({"Model Name": ["No data available"]})
today_date = datetime.now(timezone.utc).strftime("%d.%m.%Y")
human_arena_label = f"Human Arena Results Updated At {today_date}"
human_arena_table = gr.DataFrame(
value=human_arena_df,
label=human_arena_label,
interactive=False,
column_widths=["300px", "150px", "110px", "110px", "110px", "156px", "169px", "100px", "120px"]
)
general_btn.click(
fn=lambda data: filter_human_arena_table("general", data),
inputs=[human_arena_state],
outputs=[human_arena_table, active_category_state, general_btn, reasoning_btn]
)
reasoning_btn.click(
fn=lambda data: filter_human_arena_table("reasoning", data),
inputs=[human_arena_state],
outputs=[human_arena_table, active_category_state, general_btn, reasoning_btn]
)
with gr.TabItem("🏆 Leaderboard"):
# Birleşik leaderboard tablosu - avg_json dosyalarındaki tüm bilgileri göster
# Only use default data (avg files) for the leaderboard
combined_df = create_combined_leaderboard_table(benchmark_results)
# Float değerleri formatlama
combined_df = format_dataframe(combined_df)
# Tüm sütunları göster
if not combined_df.empty:
leaderboard_df = combined_df.copy()
else:
leaderboard_df = pd.DataFrame({"Model Name": ["No data available"]})
# Orijinal veriyi saklayacak state değişkeni
original_leaderboard_data = gr.State(value=leaderboard_df)
combined_table = gr.DataFrame(
value=leaderboard_df,
label="Model Performance Comparison",
interactive=False,
column_widths=["300px", "165px" ,"165px", "120px", "120px", "180px", "220px", "100px", "100px", "120px"]
)
with gr.TabItem("🏟️ Auto Arena"):
arena_details_df = create_raw_details_table(benchmark_results, "arena")
arena_details_df = format_dataframe(arena_details_df)
if arena_details_df.empty:
arena_details_df = pd.DataFrame({"model_name": ["No data available"]})
arena_table = gr.DataFrame(
value=arena_details_df,
label="Arena Detailed Results",
interactive=False,
column_widths=["300px", "150px", "110px", "110px", "180px", "100px", "120px"]
)
with gr.TabItem("📚 Retrieval"):
rag_details_df = create_raw_details_table(benchmark_results, "retrieval")
rag_details_df = format_dataframe(rag_details_df)
if rag_details_df.empty:
rag_details_df = pd.DataFrame({"model_name": ["No data available"]})
rag_table = gr.DataFrame(
value=rag_details_df,
label="Retrieval Detailed Results",
interactive=False,
column_widths=["280px", "120px", "140px", "140px", "140px", "120px", "160px", "100px", "120px"]
)
with gr.TabItem("🔧 Structured Outputs"):
structured_details_df = create_structured_outputs_table(benchmark_results["raw"]["structured_output"], is_detail=True)
if structured_details_df.empty:
structured_details_df = pd.DataFrame({"Model": ["No data available"]})
structured_table = gr.DataFrame(
value=structured_details_df,
label="Structured Outputs Detailed Results",
interactive=False,
column_widths=["300px", "250px", "110px", "150px", "100px", "150px", "150px", "100px", "100px", "100px", "120px"]
)
with gr.TabItem("⚡ Light Eval"):
light_details_data = benchmark_results["raw"]["light_eval"]
if light_details_data:
light_details_df = create_light_eval_table(light_details_data, is_detail=True)
else:
light_details_df = pd.DataFrame()
light_details_df = format_dataframe(light_details_df, is_light_eval_detail=True)
if light_details_df.empty:
light_details_df = pd.DataFrame({"model_name": ["No data available"]})
light_table = gr.DataFrame(
value=light_details_df,
label="Light Eval Detailed Results",
interactive=False,
column_widths=["300px", "110px", "110px", "143px", "130px", "130px", "110px", "110px", "100px", "120px"]
)
with gr.TabItem("📋 EvalMix"):
hybrid_details_df = create_raw_details_table(benchmark_results, "evalmix")
hybrid_details_df = format_dataframe(hybrid_details_df)
if hybrid_details_df.empty:
hybrid_details_df = pd.DataFrame({"model_name": ["No data available"]})
hybrid_table = gr.DataFrame(
value=hybrid_details_df,
label="EvalMix Detailed Results",
interactive=False,
column_widths=["300px", "180px", "230px", "143px", "110px", "110px", "110px", "110px", "169px", "220px" ,"100px", "120px"]
)
with gr.TabItem("🐍 𝐒𝐧𝐚𝐤𝐞 𝐁𝐞𝐧𝐜𝐡"):
snake_details_df = create_raw_details_table(benchmark_results, "snake")
snake_details_df = format_dataframe(snake_details_df)
if snake_details_df.empty:
snake_details_df = pd.DataFrame({"model_name": ["No data available"]})
snake_table = gr.DataFrame(
value=snake_details_df,
label="Snake Benchmark Detailed Results",
interactive=False,
column_widths=["300px", "130px", "110px", "117px", "110px", "110px", "110px", "117px", "100px", "120px"]
)
# with gr.TabItem("📊 LM-Harness"):
# # LM Harness sonuçları - detail dosyalarını kullan
# lmharness_details_df = create_raw_details_table(benchmark_results, "lm_harness")
# lmharness_details_df = format_dataframe(lmharness_details_df)
#
# if lmharness_details_df.empty:
# lmharness_details_df = pd.DataFrame({"model_name": ["No data available"]})
#
# lmharness_table = gr.DataFrame(
# value=lmharness_details_df,
# label="LM Harness Detailed Results",
# interactive=False
# )
# # Refresh butonu bağlantısı
# refresh_button.click(
# refresh_leaderboard,
# inputs=[],
# outputs=[
# refresh_status,
# combined_table,
# hybrid_table,
# rag_table,
# light_table,
# arena_table,
# lmharness_table,
# snake_table
# ]
# )
def search_all_tabs(query, original_data):
"""
Search across all tabs
"""
if not query or query.strip() == "":
return (original_data, arena_details_df, human_arena_df,
rag_details_df, structured_details_df, light_details_df, hybrid_details_df, snake_details_df)
return (
search_and_filter(query, original_data, "All"),
search_and_filter(query, arena_details_df, "All"),
search_and_filter(query, human_arena_df, "All"),
search_and_filter(query, rag_details_df, "All"),
search_and_filter(query, structured_details_df, "All"),
search_and_filter(query, light_details_df, "All"),
search_and_filter(query, hybrid_details_df, "All"),
search_and_filter(query, snake_details_df, "All")
)
search_input.change(
search_all_tabs,
inputs=[search_input, original_leaderboard_data],
outputs=[combined_table, arena_table, human_arena_table, rag_table, structured_table, light_table, hybrid_table, snake_table]
)
with gr.TabItem("ℹ️ About", elem_id="about-tab"):
gr.Markdown(LLM_BENCHMARKS_TEXT, elem_classes="markdown-text")
with gr.TabItem("📊 Datasets", elem_id="datasets-tab"):
gr.Markdown("## Benchmark Datasets")
gr.Markdown("""
This section provides detailed information about the datasets used in our evaluation benchmarks.
Each dataset has been carefully selected and adapted to provide comprehensive model evaluation across different domains and capabilities.
""")
# Create and display the datasets table
datasets_html = """
<div style="margin-top: 20px;">
<h3>Available Datasets for Evaluation</h3>
<table style="width: 100%; border-collapse: collapse; margin-top: 10px;">
<thead>
<tr style="background-color: var(--background-fill-secondary);">
<th style="padding: 12px; text-align: left; border-bottom: 2px solid var(--border-color-primary); width: 20%;">Dataset</th>
<th style="padding: 12px; text-align: left; border-bottom: 2px solid var(--border-color-primary); width: 18%;">Evaluation Task</th>
<th style="padding: 12px; text-align: left; border-bottom: 2px solid var(--border-color-primary); width: 10%;">Language</th>
<th style="padding: 12px; text-align: left; border-bottom: 2px solid var(--border-color-primary); width: 52%;">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 20%;"><a href="https://huggingface.co/datasets/malhajar/mmlu_tr-v0.2" target="_blank" style="color: #0066cc; text-decoration: none;">malhajar/mmlu_tr-v0.2</a></td>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 18%;">Lighteval MMLU</td>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 10%;">Turkish</td>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 52%;">Turkish adaptation of MMLU (Massive Multitask Language Understanding) v0.2 covering 57 academic subjects including mathematics, physics, chemistry, biology, history, law, and computer science. Tests knowledge and reasoning capabilities across multiple domains with multiple-choice questions.</td>
</tr>
<tr>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 20%;"><a href="https://huggingface.co/datasets/malhajar/truthful_qa-tr-v0.2" target="_blank" style="color: #0066cc; text-decoration: none;">malhajar/truthful_qa-tr-v0.2</a></td>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 18%;">Lighteval TruthfulQA</td>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 10%;">Turkish</td>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 52%;">Turkish version of TruthfulQA (v0.2) designed to measure model truthfulness and resistance to generating false information. Contains questions where humans often answer incorrectly due to misconceptions or false beliefs, testing the model's ability to provide accurate information.</td>
</tr>
<tr>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 20%;"><a href="https://huggingface.co/datasets/malhajar/winogrande-tr-v0.2" target="_blank" style="color: #0066cc; text-decoration: none;">malhajar/winogrande-tr-v0.2</a></td>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 18%;">Lighteval WinoGrande</td>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 10%;">Turkish</td>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 52%;">Turkish adaptation of WinoGrande (v0.2) focusing on commonsense reasoning through pronoun resolution tasks. Tests the model's ability to understand context, make logical inferences, and resolve ambiguous pronouns in everyday scenarios.</td>
</tr>
<tr>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 20%;"><a href="https://huggingface.co/datasets/malhajar/hellaswag_tr-v0.2" target="_blank" style="color: #0066cc; text-decoration: none;">malhajar/hellaswag_tr-v0.2</a></td>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 18%;">Lighteval HellaSwag</td>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 10%;">Turkish</td>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 52%;">Turkish version of HellaSwag (v0.2) for commonsense reasoning evaluation. Tests the model's ability to predict plausible continuations of everyday scenarios and activities, requiring understanding of common sense and typical human behavior patterns.</td>
</tr>
<tr>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 20%;"><a href="https://huggingface.co/datasets/malhajar/arc-tr-v0.2" target="_blank" style="color: #0066cc; text-decoration: none;">malhajar/arc-tr-v0.2</a></td>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 18%;">Lighteval ARC</td>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 10%;">Turkish</td>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 52%;">Turkish adaptation of ARC (AI2 Reasoning Challenge) v0.2 focusing on science reasoning and question answering. Contains grade school level science questions that require reasoning beyond simple factual recall, covering topics in physics, chemistry, biology, and earth science.</td>
</tr>
<tr>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 20%;"><a href="https://huggingface.co/datasets/malhajar/gsm8k_tr-v0.2" target="_blank" style="color: #0066cc; text-decoration: none;">malhajar/gsm8k_tr-v0.2</a></td>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 18%;">Lighteval GSM8K</td>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 10%;">Turkish</td>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 52%;">Turkish version of GSM8K (Grade School Math 8K) v0.2 for mathematical reasoning evaluation. Contains grade school level math word problems that require multi-step reasoning, arithmetic operations, and logical problem-solving skills to arrive at the correct numerical answer.</td>
</tr>
<tr>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 20%;"><a href="https://huggingface.co/datasets/newmindai/mezura-eval-data" target="_blank" style="color: #0066cc; text-decoration: none;">newmindai/mezura-eval-data</a></td>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 18%;">Auto-Arena</td>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 10%;">Turkish</td>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 52%;">mezura-eval dataset is a Turkish-language legal text dataset designed for evaluation tasks with RAG context support. The subsets include domains like Environmental Law, Tax Law, Data Protection Law and Health Law each containing annotated samples. Every row includes structured fields such as the category, concept, input and contextual information drawn from sources like official decisions.</td>
</tr>
<tr>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 20%;"><a href="https://huggingface.co/datasets/newmindai/mezura-eval-data" target="_blank" style="color: #0066cc; text-decoration: none;">newmindai/mezura-eval-data</a></td>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 18%;">EvalMix</td>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 10%;">Turkish</td>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 52%;">mezura-eval dataset is a Turkish-language legal text dataset designed for evaluation tasks with RAG context support. The subsets include domains like Environmental Law, Tax Law, Data Protection Law and Health Law each containing annotated samples. Every row includes structured fields such as the category, concept, input and contextual information drawn from sources like official decisions.</td>
</tr>
<tr>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 20%;"><a href="https://huggingface.co/datasets/newmindai/mezura-eval-data" target="_blank" style="color: #0066cc; text-decoration: none;">newmindai/mezura-eval-data</a></td>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 18%;">Retrieval</td>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 10%;">Turkish</td>
<td style="padding: 10px; border-bottom: 1px solid var(--border-color-primary); width: 52%;">mezura-eval dataset is a Turkish-language legal text dataset designed for evaluation tasks with RAG context support. The subsets include domains like Environmental Law, Tax Law, Data Protection Law and Health Law each containing annotated samples. Every row includes structured fields such as the category, concept, input and contextual information drawn from sources like official decisions.</td>
</tr>
</tbody>
</table>
</div>
"""
gr.HTML(datasets_html)
with gr.TabItem("🔬 Evaluation", elem_id="evaluation-tab"):
gr.Markdown("""
<h2 align="center">Model Evaluation</h2>
### Evaluation Process:
1. **Login to Your Hugging Face Account**
- You must be logged in to submit models for evaluation
2. **Enter Model Name**
- Input the HuggingFace model name or path you want to evaluate
- Example: meta-llama/Meta-Llama-3.1-70B-Instruct
3. **Select Base Model**
- Choose the base model from the dropdown list
- The system will verify if your repository is a valid HuggingFace repository
- It will check if the model is trained from the selected base model
4. **Start Evaluation**
- Click the "Start All Benchmarks" button to begin the evaluation
- If validation passes, your request will be processed
- If validation fails, you'll see an error message
### Important Limitations:
- The model repository must be a maximum of 750 MB in size.
- For trained adapters, the maximum LoRA rank must be 32.
""")
# Authentication Component (Always visible)
auth_container = gr.Group()
with auth_container:
# Simplified login button - Gradio will handle the OAuth
login_button = gr.LoginButton()
# Get base models from API
from api.config import get_base_model_list
BASE_MODELS = get_base_model_list()
# Fallback to static list if API list is empty
if not BASE_MODELS:
BASE_MODELS = [
"meta-llama/Meta-Llama-3.1-8B-Instruct",
"meta-llama/Llama-3.2-3B-Instruct",
"meta-llama/Llama-3.3-70B-Instruc",
"Qwen/Qwen2.5-72B-Instruct",
"Qwen/QwQ-32B",
"google/gemma-2-2b-it"
]
# Content that's only visible when logged in
login_dependent_content = gr.Group(visible=False)
with login_dependent_content:
gr.Markdown("### Model Submission")
# Model input
model_to_evaluate = gr.Textbox(
label="Adapter Repo ID",
placeholder="e.g., valadapt/llama-3-8b-turkish"
)
# Add note about supported model types
gr.Markdown("""
**Note:** Currently, only adapter models are supported. Merged models are not yet supported.
""", elem_classes=["info-text"])
# Base model selection
base_model_dropdown = gr.Dropdown(
choices=BASE_MODELS,
label="Base Model",
allow_custom_value=True
)
# Reasoning capability checkbox
reasoning_checkbox = gr.Checkbox(
label="Reasoning",
value=False,
info="Enable reasoning capability during evaluation"
)
# Email input
email_input = gr.Textbox(
label="Email Address",
placeholder="example@domain.com",
info="You'll receive notification when benchmark is complete"
)
# Submit button - CRITICAL: This submit button is only visible when logged in
submit_button = gr.Button("Start All Benchmarks", variant="primary")
# Result area (initially empty)
result_output = gr.Markdown("")
# Status area for authentication errors (initially hidden)
auth_error = gr.Markdown(visible=False)
# Function to handle login visibility
def toggle_form_visibility(profile):
# User is not logged in
if profile is None:
return (
gr.update(visible=False),
gr.update(
visible=True,
value="<p style='color: red; text-align: center; font-weight: bold;'>Authentication required. Please log in with your Hugging Face account to submit models.</p>"
)
)
# Log successful authentication
try:
if hasattr(profile, 'name'):
username = profile.name
elif hasattr(profile, 'username'):
username = profile.username
else:
username = str(profile)
logger.info(f"User authenticated: {username}")
except Exception as e:
logger.info(f"LOGIN - Error inspecting profile: {str(e)}")
# User is logged in - show form, hide error
return (
gr.update(visible=True),
gr.update(visible=False, value="")
)
# Connect login button to visibility toggle
login_button.click(
fn=toggle_form_visibility,
inputs=[login_button],
outputs=[login_dependent_content, auth_error]
)
# Check visibility on page load
demo.load(
fn=toggle_form_visibility,
inputs=[login_button],
outputs=[login_dependent_content, auth_error]
)
# Handle submission with authentication check
def submit_model(model, base_model, reasoning, email, profile):
# Authentication check
if profile is None:
logging.warning("Unauthorized submission attempt with no profile")
return "<p style='color: red; font-weight: bold;'>Authentication required. Please log in with your Hugging Face account.</p>"
# IMPORTANT: In local development, Gradio returns "Sign in with Hugging Face" string
# This is NOT a real authentication, just a placeholder for local testing
if isinstance(profile, str) and profile == "Sign in with Hugging Face":
# Block submission in local dev with mock auth
return "<p style='color: orange; font-weight: bold;'>⚠️ HF authentication required.</p>"
# Email is required
if not email or email.strip() == "":
return "<p style='color: red; font-weight: bold;'>Email address is required to receive benchmark results.</p>"
# Check if the model is a merged model (not supported)
try:
from src.submission.check_validity import determine_model_type
model_type, _ = determine_model_type(model)
if model_type == "merged_model" or model_type == "merge":
return "<p style='color: red; font-weight: bold;'>Merged models are not supported yet. Please submit an adapter model instead.</p>"
except Exception as e:
# If error checking model type, continue with submission
logging.warning(f"Error checking model type: {str(e)}")
# Call the benchmark function with profile information
result_message, _ = submit_unified_benchmark(model, base_model, reasoning, email, profile)
logging.info(f"Submission processed for model: {model}")
return result_message
# Connect submit button
submit_button.click(
fn=submit_model,
inputs=[
model_to_evaluate,
base_model_dropdown,
reasoning_checkbox,
email_input,
login_button
],
outputs=[result_output]
)
except Exception as e:
traceback.print_exc()
gr.Markdown(f"## Error: An issue occurred while loading the LLM Benchmark screen")
gr.Markdown(f"Error message: {str(e)}")
gr.Markdown("Please check your configuration and try again.")
# Citation information at the bottom
gr.Markdown("---")
with gr.Accordion(CITATION_BUTTON_LABEL, open=False):
gr.Textbox(
value=CITATION_BUTTON_TEXT,
lines=10,
show_copy_button=True,
label=None
)
return demo
if __name__ == "__main__":
# Get app logger
logger = logging.getLogger("mezura")
# Additional sensitive filter for remaining logs
class SensitiveFilter(logging.Filter):
def filter(self, record):
msg = record.getMessage().lower()
# Filter out messages with tokens, URLs with sign= in them, etc
sensitive_patterns = ["token", "__sign=", "request", "auth", "http request"]
return not any(pattern in msg.lower() for pattern in sensitive_patterns)
# Apply the filter to all loggers
for logger_name in logging.root.manager.loggerDict:
logging.getLogger(logger_name).addFilter(SensitiveFilter())
try:
logger.info("Creating demo...")
demo = create_demo()
logger.info("Launching demo on 0.0.0.0...")
# Add options to fix the session.pop error
demo.launch(
server_name="0.0.0.0",
server_port=7860
)
except FileNotFoundError as e:
logger.critical(f"Configuration file not found: {e}")
print(f"\n\nERROR: Configuration file not found. Please ensure config/api_config.yaml exists.\n{e}\n")
sys.exit(1)
except ValueError as e:
logger.critical(f"Configuration error: {e}")
print(f"\n\nERROR: Invalid configuration. Please check your config/api_config.yaml file.\n{e}\n")
sys.exit(1)
except Exception as e:
logger.critical(f"Could not launch demo: {e}", exc_info=True)