File size: 1,876 Bytes
be77ede
8e5ef5f
be77ede
 
 
 
 
5fe42e9
be77ede
 
 
 
 
 
 
8e5ef5f
 
be77ede
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# app.py
import gradio as gr
import json
from evaluate import evaluate_model, load_dataset
from datetime import datetime

# Load dataset once
dataset = load_dataset("arshiaafshani/persian-natural-fluently", split="train[:10]")

# Load or initialize leaderboard
try:
    with open("leaderboard.json", "r", encoding="utf-8") as f:
        leaderboard = json.load(f)
except FileNotFoundError:
    leaderboard = []

def submit_model(model_name):
    score = evaluate_model(model_name, dataset)
    leaderboard.append({
        "model": model_name,
        "score": round(score * 100, 2),
        "date": datetime.now().strftime("%Y-%m-%d")
    })
    leaderboard.sort(key=lambda x: x["score"], reverse=True)
    with open("leaderboard.json", "w", encoding="utf-8") as f:
        json.dump(leaderboard, f, ensure_ascii=False, indent=2)
    return update_table()

def update_table():
    headers = ["πŸ… Rank", "πŸ“Œ Model Name", "🎯 Score", "πŸ“† Date"]
    rows = [[i + 1, row["model"], f"{row['score']}%", row["date"]] for i, row in enumerate(leaderboard)]
    return headers, rows

with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
    gr.Markdown("""
    # πŸ† Persian Embedding Leaderboard
    Submit your model to evaluate on the [arshiaafshani/persian-natural-fluently](https://huggingface.co/datasets/arshiaafshani/persian-natural-fluently) dataset.
    """)

    with gr.Row():
        model_input = gr.Textbox(label="Enter HuggingFace Model Name", placeholder="e.g. HooshvareLab/bert-fa-base-uncased")
        submit_btn = gr.Button("Evaluate & Submit")

    table = gr.Dataframe(headers=["πŸ… Rank", "πŸ“Œ Model Name", "🎯 Score", "πŸ“† Date"],
                         value=update_table()[1],
                         interactive=False)

    submit_btn.click(fn=submit_model, inputs=model_input, outputs=table)

if __name__ == "__main__":
    demo.launch()