File size: 1,436 Bytes
d22a7f8
475174a
 
 
 
b2d42ac
d22a7f8
b2d42ac
 
 
 
8fb7a79
 
 
53ea54b
8fb7a79
475174a
b2d42ac
 
475174a
 
 
b2d42ac
475174a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import pandas as pd
from evaluation import evaluate_submission
import os
import datetime
import sys

# Make sure current directory includes parent of 'source'
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

LEADERBOARD_FILE = os.path.join(os.path.dirname(__file__), "..", "leaderboard.csv")

st.title("πŸ† Hackathon Leaderboard")

uploaded_file = st.file_uploader("Upload your submission (.py)")

if uploaded_file:
    temp_path = os.path.join(os.path.dirname(__file__), "submission_temp.py")
    with open(temp_path, "wb") as f:
        f.write(uploaded_file.read())

    try:
        score = evaluate_submission(temp_path)  # Implement this
        timestamp = datetime.datetime.now().isoformat()
        entry = {"filename": uploaded_file.name, "score": score, "timestamp": timestamp}

        # Save to leaderboard
        if os.path.exists(LEADERBOARD_FILE):
            df = pd.read_csv(LEADERBOARD_FILE)
            df = df.append(entry, ignore_index=True)
        else:
            df = pd.DataFrame([entry])
        df.to_csv(LEADERBOARD_FILE, index=False)
        st.success(f"Submission scored {score}!")
    except Exception as e:
        st.error(f"Error: {e}")

# Show leaderboard
if os.path.exists(LEADERBOARD_FILE):
    df = pd.read_csv(LEADERBOARD_FILE)
    df = df.sort_values(by="score", ascending=False)
    st.subheader("πŸ… Leaderboard")
    st.dataframe(df)