Mehrdad-S's picture
Update app.py
5fe42e9 verified
raw
history blame
1.88 kB
# 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()