Spaces:
Running
Running
import gradio as gr | |
from pathlib import Path | |
import logging | |
# Import LeaderboardApp from the correct location within the 'leaderboard' package | |
from leaderboard.leaderboard import LeaderboardApp | |
# Import UI rendering functions for other tabs | |
from about import render_about | |
from submission import render_submit | |
# --- Logging Setup (Optional but Recommended) --- | |
# You can centralize logging configuration here or ensure each module handles its own. | |
# For simplicity, if other modules already configure logging, this might not be strictly needed here. | |
logging.basicConfig( | |
level=logging.INFO, | |
format="%(asctime)s - %(levelname)s - %(module)s - %(message)s" | |
) | |
logger = logging.getLogger(__name__) | |
def create_app(): | |
""" | |
Creates and configures the main Gradio application for MIZAN: A Persian LLM Leaderboard. | |
""" | |
logger.info("Initializing MIZAN: A Persian LLM Leaderboard application...") | |
# Define the path to the leaderboard's configuration file | |
# This assumes app.py is in the project root, and leaderboard_config.yaml is inside the 'leaderboard' directory. | |
config_file_path = Path("leaderboard/leaderboard_config.yaml") | |
if not config_file_path.exists(): | |
logger.error(f"CRITICAL: Leaderboard configuration file not found at {config_file_path}. The application may not function correctly.") | |
# Optionally, you could raise an error here or return a Gradio interface indicating the error. | |
# Initialize the LeaderboardApp with the configuration path | |
leaderboard_processor = LeaderboardApp(config_path=config_file_path) | |
# Load and process data for the leaderboard | |
logger.info("Loading and processing leaderboard data...") | |
leaderboard_processor.load_data() | |
leaderboard_processor.handle_nulls_in_averages() | |
leaderboard_processor.generate_model_rankings() | |
# leaderboard_processor.apply_rankings_to_dataframes() # This might be redundant if generate_model_rankings covers it | |
# leaderboard_processor.format_dataframes() | |
logger.info("Leaderboard data processing complete.") | |
# Create the main Gradio interface using gr.Blocks | |
with gr.Blocks(title="MIZAN: A Persian LLM Leaderboard") as demo: | |
gr.Markdown("<h1 style='text-align: center; width: 100%; margin-bottom: 10px;'>🇮🇷 MIZAN: A Persian LLM Leaderboard</h1>") | |
gr.Markdown("""<p style='font-size: 1.1em; text-align: center; max-width: 800px; margin: 0 auto 20px auto;'> | |
MIZAN: A Persian LLM Leaderboard is a comprehensive benchmark for evaluating Large Language Models (LLMs) in Persian. | |
It combines existing datasets, translated benchmarks, and new Persian-specific data to assess LLM capabilities in understanding, | |
generation, reasoning, and knowledge relevant to the Persian language and culture. | |
MIZAN provides a standardized tool for researchers and developers to measure Persian LLM performance. | |
</p>""") | |
with gr.Tabs(): | |
with gr.TabItem("LLM Benchmark"): | |
logger.info("Creating 'LLM Benchmark' tab content...") | |
# Embed the leaderboard interface generated by LeaderboardApp | |
# The create_gradio_interface method of LeaderboardApp should return a gr.Blocks or gr.Interface instance | |
leaderboard_processor.create_gradio_interface() # This directly adds its components to the current gr.Blocks scope | |
logger.info("'LLM Benchmark' tab content created.") | |
with gr.TabItem("About MIZAN"): # Changed from "About PULL" | |
logger.info("Creating 'About MIZAN' tab content...") # Changed from "About PULL" | |
render_about() # Call the function that returns the 'About' page Blocks | |
logger.info("'About MIZAN' tab content created.") # Changed from "About PULL" | |
with gr.TabItem("Request New Model"): | |
logger.info("Creating 'Submit Your Model' tab content...") | |
render_submit() # Call the function that returns the 'Submit' page Blocks | |
logger.info("'Submit Your Model' tab content created.") | |
logger.info("MIZAN: A Persian LLM Leaderboard application interface created.") # Changed from "PULL Leaderboard" | |
return demo | |
if __name__ == "__main__": | |
logger.info("Launching MIZAN: A Persian LLM Leaderboard application...") # Changed from "PULL Leaderboard" | |
pull_app = create_app() # Variable name 'pull_app' kept as is, but can be changed if desired e.g., to 'mizan_app' | |
pull_app.launch( | |
debug=True, # Enable Gradio debug mode for more detailed error messages in development | |
share=True # Uncomment to create a public link (useful for temporary sharing) | |
# server_name="0.0.0.0" # Uncomment to make accessible on your local network | |
) | |
logger.info("MIZAN: A Persian LLM Leaderboard application has been launched.") # Changed from "PULL Leaderboard" | |
# Ensure there are no hidden/invalid characters after this line. A single newline character is standard. | |