Spaces:
Sleeping
Sleeping
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() |