File size: 6,800 Bytes
a2c34b1
b064a39
 
 
a2c34b1
b064a39
 
a2c34b1
 
 
b064a39
a2c34b1
b064a39
 
a2c34b1
 
 
 
 
 
2deac9d
b064a39
a2c34b1
 
 
 
 
 
 
 
 
 
 
 
 
 
b064a39
a2c34b1
 
 
 
 
 
 
 
 
 
 
 
 
 
b064a39
a2c34b1
 
 
 
 
 
 
 
 
 
 
b064a39
a2c34b1
b064a39
a2c34b1
 
 
b064a39
a2c34b1
 
 
 
 
 
b064a39
 
 
a2c34b1
 
b064a39
a2c34b1
 
 
 
 
 
 
 
b064a39
 
a2c34b1
b064a39
a2c34b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b064a39
a2c34b1
 
 
 
 
 
 
 
 
b064a39
a2c34b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2deac9d
a2c34b1
 
 
 
 
 
 
 
 
 
 
 
 
 
b064a39
a2c34b1
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187

import gradio as gr
import pandas as pd
import json
from pathlib import Path
from datetime import datetime, timezone

LAST_UPDATED = "Dec 4th 2024"
QUEUE_DIR = Path("/Users/arunasrivastava/Koel/IPA-Leaderboard/IPA-Transcription-EN-queue/queue")
APP_DIR = Path("./")

# Modified column names for phonemic transcription metrics
column_names = {
    "MODEL": "Model",
    "SUBMISSION_NAME": "Submission Name",
    "AVG_PER": "Average PER โฌ‡๏ธ",    
    "AVG_PFER": "Average PFER โฌ‡๏ธ",
    "SUBSET": "Dataset Subset",
    "GITHUB_URL": "GitHub",
    "DATE": "Submission Date"
}

def load_leaderboard_data():
    leaderboard_path = QUEUE_DIR / "leaderboard.json"
    if not leaderboard_path.exists():
        print(f"Warning: Leaderboard file not found at {leaderboard_path}")
        return pd.DataFrame()
        
    try:
        with open(leaderboard_path, 'r') as f:
            data = json.load(f)
        df = pd.DataFrame(data)
        return df
    except Exception as e:
        print(f"Error loading leaderboard data: {e}")
        return pd.DataFrame()

def format_leaderboard_df(df):
    if df.empty:
        return df
        
    # Rename columns to display names
    display_df = df.rename(columns={
        "model": "MODEL",
        "submission_name": "SUBMISSION_NAME",
        "average_per": "AVG_PER",
        "average_pfer": "AVG_PFER",
        "subset": "SUBSET",
        "github_url": "GITHUB_URL",
        "submission_date": "DATE"
    })
    
    # Format numeric columns
    display_df["AVG_PER"] = display_df["AVG_PER"].apply(lambda x: f"{x:.4f}")
    display_df["AVG_PFER"] = display_df["AVG_PFER"].apply(lambda x: f"{x:.4f}")
    
    # Make GitHub URLs clickable
    display_df["GITHUB_URL"] = display_df["GITHUB_URL"].apply(
        lambda x: f'<a href="{x}" target="_blank">Repository</a>' if x else "N/A"
    )
    
    # Sort by PER (ascending)
    display_df.sort_values(by="AVG_PER", inplace=True)
    
    return display_df

def request_evaluation(model_name, submission_name, github_url, subset="test", max_samples=5):
    if not model_name or not submission_name:
        return gr.Markdown("โš ๏ธ Please provide both model name and submission name.")
        
    request_data = {
        "transcription_model": model_name,
        "subset": subset,
        "max_samples": max_samples,
        "submission_name": submission_name,
        "github_url": github_url or ""
    }
    
    try:
        # Ensure queue directory exists
        QUEUE_DIR.mkdir(parents=True, exist_ok=True)
        
        # Generate unique timestamp for request file
        timestamp = datetime.now(timezone.utc).isoformat().replace(":", "-")
        request_file = QUEUE_DIR / f"request_{timestamp}.json"
        
        with open(request_file, 'w') as f:
            json.dump(request_data, f, indent=2)
            
        return gr.Markdown("โœ… Evaluation request submitted successfully! Your results will appear on the leaderboard once processing is complete.")
        
    except Exception as e:
        return gr.Markdown(f"โŒ Error submitting request: {str(e)}")

def load_results_for_model(model_name):
    results_path = QUEUE_DIR / "results.json"
    try:
        with open(results_path, 'r') as f:
            results = json.load(f)
            
        # Filter results for the specific model
        model_results = [r for r in results if r["model"] == model_name]
        if not model_results:
            return None
            
        # Get the most recent result
        latest_result = max(model_results, key=lambda x: x["timestamp"])
        return latest_result
    except Exception as e:
        print(f"Error loading results: {e}")
        return None

# Create Gradio interface
with gr.Blocks() as demo:
    gr.Markdown("# ๐ŸŽฏ Phonemic Transcription Model Evaluation Leaderboard")
    gr.Markdown("""
        Compare the performance of different phonemic transcription models on speech-to-IPA transcription tasks.
        
        **Metrics:**
        - **PER (Phoneme Error Rate)**: Measures the edit distance between predicted and ground truth phonemes (lower is better)
        - **PFER (Phoneme Frame Error Rate)**: Measures frame-level phoneme prediction accuracy (lower is better)
    """)
    
    with gr.Tabs() as tabs:
        with gr.TabItem("๐Ÿ† Leaderboard"):
            leaderboard_df = load_leaderboard_data()
            formatted_df = format_leaderboard_df(leaderboard_df)
            
            leaderboard_table = gr.DataFrame(
                value=formatted_df,
                interactive=False,
                headers=list(column_names.values())
            )
            
            refresh_btn = gr.Button("๐Ÿ”„ Refresh Leaderboard")
            refresh_btn.click(
                lambda: gr.DataFrame(value=format_leaderboard_df(load_leaderboard_data()))
            )
            
        with gr.TabItem("๐Ÿ“ Submit Model"):
            with gr.Column():
                model_input = gr.Textbox(
                    label="Model Name",
                    placeholder="facebook/wav2vec2-lv-60-espeak-cv-ft",
                    info="Enter the Hugging Face model ID"
                )
                submission_name = gr.Textbox(
                    label="Submission Name",
                    placeholder="My Awesome Model v1.0",
                    info="Give your submission a descriptive name"
                )
                github_url = gr.Textbox(
                    label="GitHub Repository URL (optional)",
                    placeholder="https://github.com/username/repo",
                    info="Link to your model's code repository"
                )
                
                submit_btn = gr.Button("๐Ÿš€ Submit for Evaluation")
                result_text = gr.Markdown()
                
                submit_btn.click(
                    request_evaluation,
                    inputs=[model_input, submission_name, github_url],
                    outputs=result_text
                )
        
        with gr.TabItem("โ„น๏ธ Detailed Results"):
            model_selector = gr.Textbox(
                label="Enter Model Name to View Details",
                placeholder="facebook/wav2vec2-lv-60-espeak-cv-ft"
            )
            view_btn = gr.Button("View Results")
            results_json = gr.JSON(label="Detailed Results")
            
            def show_model_results(model_name):
                results = load_results_for_model(model_name)
                return results or {"error": "No results found for this model"}
            
            view_btn.click(
                show_model_results,
                inputs=[model_selector],
                outputs=[results_json]
            )
    
    gr.Markdown(f"Last updated: {LAST_UPDATED}")

demo.launch()