File size: 2,016 Bytes
50a8af6
dc8d315
50a8af6
dc8d315
 
 
88ad01d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dc8d315
 
88ad01d
 
dc8d315
 
 
 
 
 
 
 
 
 
 
 
 
88ad01d
dc8d315
 
 
 
 
 
 
 
50a8af6
 
dc8d315
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
import gradio as gr
from evaluate import run_evaluation
import pandas as pd
import os

LEADERBOARD_CSV = "leaderboard.csv"
import pandas as pd
import os
from datetime import datetime, date

SUBMIT_RECORD = "submissions.csv"
MAX_SUBMIT_PER_DAY = 2

def check_submission_limit(username):
    if not os.path.exists(SUBMIT_RECORD):
        return True  # 没有人提交过

    df = pd.read_csv(SUBMIT_RECORD)
    today = date.today()

    user_today_subs = df[
        (df["username"] == username) &
        (pd.to_datetime(df["timestamp"]).dt.date == today)
    ]

    return len(user_today_subs) < MAX_SUBMIT_PER_DAY

def record_submission(username):
    now = datetime.now().isoformat()
    if os.path.exists(SUBMIT_RECORD):
        df = pd.read_csv(SUBMIT_RECORD)
    else:
        df = pd.DataFrame(columns=["username", "timestamp"])
    df.loc[len(df)] = {"username": username, "timestamp": now}
    df.to_csv(SUBMIT_RECORD, index=False)

def evaluate_and_update(pred_file, username):
    if not check_submission_limit(username):
        return "⛔ Submission limit exceeded for today.", pd.read_csv(LEADERBOARD_CSV)
    score = run_evaluation(pred_file.name)
    if os.path.exists(LEADERBOARD_CSV):
        df = pd.read_csv(LEADERBOARD_CSV)
    else:
        df = pd.DataFrame(columns=["name", "score"])
    df.loc[len(df)] = {"name": username, "score": score}
    df = df.sort_values(by="score", ascending=False).reset_index(drop=True)
    df.to_csv(LEADERBOARD_CSV, index=False)
    return f"Your score: {score:.4f}", df

with gr.Blocks() as demo:
    gr.Markdown("# 🧊 3D IoU Challenge")
    name = gr.Textbox(label="Username")
    upload = gr.File(label="Upload your prediction (.json)")
    score_text = gr.Textbox(label="Evaluation score")
    leaderboard = gr.Dataframe(headers=["Name", "Score"], interactive=False)

    submit_btn = gr.Button("Submit")
    submit_btn.click(
        fn=evaluate_and_update,
        inputs=[upload, name],
        outputs=[score_text, leaderboard]
    )

demo.launch()