|
|
import gradio as gr |
|
|
import pandas as pd |
|
|
import os |
|
|
|
|
|
CSV_PATH = "results.csv" |
|
|
|
|
|
|
|
|
if not os.path.exists(CSV_PATH): |
|
|
df_init = pd.DataFrame(columns=[ |
|
|
"Model Name", "Accuracy", "F1 Score", "Inference Time (s)", "Hugging Face Link" |
|
|
]) |
|
|
df_init.to_csv(CSV_PATH, index=False) |
|
|
|
|
|
|
|
|
def submit_result(model, acc, f1, time, link): |
|
|
try: |
|
|
df = pd.read_csv(CSV_PATH) |
|
|
new_row = { |
|
|
"Model Name": model.strip(), |
|
|
"Accuracy": float(acc), |
|
|
"F1 Score": float(f1), |
|
|
"Inference Time (s)": float(time), |
|
|
"Hugging Face Link": link.strip() |
|
|
} |
|
|
updated_df = pd.concat([df, pd.DataFrame([new_row])], ignore_index=True) |
|
|
updated_df.to_csv(CSV_PATH, index=False) |
|
|
return "โ
Submitted!", updated_df |
|
|
except Exception as e: |
|
|
return f"โ Error: {str(e)}", pd.read_csv(CSV_PATH) |
|
|
|
|
|
|
|
|
with gr.Blocks() as demo: |
|
|
gr.Markdown("# ๐ Model Leaderboard + Submission") |
|
|
|
|
|
with gr.Row(): |
|
|
model = gr.Textbox(label="Model Name") |
|
|
acc = gr.Textbox(label="Accuracy (e.g. 0.89)") |
|
|
f1 = gr.Textbox(label="F1 Score (e.g. 0.87)") |
|
|
time = gr.Textbox(label="Inference Time (s)") |
|
|
link = gr.Textbox(label="Hugging Face Link") |
|
|
|
|
|
submit_btn = gr.Button("Submit Result") |
|
|
status = gr.Textbox(label="Submission Status", interactive=False) |
|
|
table = gr.Dataframe( |
|
|
value=pd.read_csv(CSV_PATH), |
|
|
headers=["Model Name", "Accuracy", "F1 Score", "Inference Time (s)", "Hugging Face Link"], |
|
|
interactive=False, |
|
|
label="Current Leaderboard" |
|
|
) |
|
|
|
|
|
submit_btn.click( |
|
|
fn=submit_result, |
|
|
inputs=[model, acc, f1, time, link], |
|
|
outputs=[status, table] |
|
|
) |
|
|
|
|
|
demo.launch() |