File size: 5,010 Bytes
fe79a14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
352d5dc
fe79a14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5d73401
fe79a14
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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.