alibayram's picture
Add configuration and data management for Gradio app, implement filtering, response search, and section results plotting functionalities
1c73b10
from typing import Optional, Dict
import pandas as pd
import matplotlib.pyplot as plt
from data_manager import data_manager
def filter_leaderboard(
family: Optional[str] = None,
quantization_level: Optional[str] = None
) -> pd.DataFrame:
"""Filter leaderboard data based on criteria."""
df = data_manager.leaderboard_data.copy()
if family:
df = df[df["family"] == family]
if quantization_level:
df = df[df["quantization_level"] == quantization_level]
return df.sort_values("score", ascending=False)
def search_responses(query: str, model: str) -> pd.DataFrame:
"""Search model responses based on query."""
if not query or not model:
return pd.DataFrame()
filtered = data_manager.responses_data[
data_manager.responses_data["bolum"].str.contains(query, case=False, na=False)
]
selected_columns = ["bolum", "soru", "cevap", f"{model}_cevap"]
return filtered[selected_columns].dropna()
def plot_section_results() -> plt.Figure:
"""Generate section results plot."""
fig, ax = plt.subplots(figsize=(12, 6))
avg_scores = data_manager.section_results_data.mean(numeric_only=True)
bars = avg_scores.plot(kind="bar", ax=ax)
# Customize plot
ax.set_title("Average Section-Wise Performance", pad=20)
ax.set_ylabel("Accuracy (%)")
ax.set_xlabel("Sections")
plt.xticks(rotation=45, ha='right')
plt.tight_layout()
# Add value labels
for i, v in enumerate(avg_scores):
ax.text(i, v, f'{v:.1f}%', ha='center', va='bottom')
return fig
def validate_model_submission(
model_name: str,
base_model: str,
revision: str,
precision: str,
weight_type: str,
model_type: str
) -> tuple[bool, str]:
"""Validate model submission parameters."""
if not all([model_name, base_model]):
return False, "Model name and base model are required."
if model_name in data_manager.leaderboard_data["model"].values:
return False, "Model name already exists."
return True, "Validation successful"