Spaces:
Sleeping
Sleeping
import streamlit as st | |
import pandas as pd | |
import os | |
import datetime | |
LEADERBOARD_FILE = "leaderboard.csv" | |
st.title("π Hackathon Leaderboard") | |
# User submission | |
uploaded_file = st.file_uploader("Upload your solution (.py)", type=["py"]) | |
username = st.text_input("Enter your team name") | |
if uploaded_file and username: | |
if st.button("Submit"): | |
# Save uploaded file (optional) | |
submission_path = f"submissions/{username}_{datetime.datetime.now().timestamp()}.py" | |
os.makedirs("submissions", exist_ok=True) | |
with open(submission_path, "wb") as f: | |
f.write(uploaded_file.read()) | |
# TODO: Add your custom evaluation logic here | |
score = 42 # Dummy score | |
# Log entry | |
timestamp = datetime.datetime.now().isoformat() | |
entry = { | |
"username": username, | |
"timestamp": timestamp, | |
"score": score, | |
"file": os.path.basename(submission_path), | |
} | |
# Append to CSV | |
if os.path.exists(LEADERBOARD_FILE): | |
df = pd.read_csv(LEADERBOARD_FILE) | |
df = pd.concat([df, pd.DataFrame([entry])], ignore_index=True) | |
else: | |
df = pd.DataFrame([entry]) | |
df.to_csv(LEADERBOARD_FILE, index=False) | |
st.success(f"Submission received! Score: {score}") | |
# Show leaderboard | |
if os.path.exists(LEADERBOARD_FILE): | |
df = pd.read_csv(LEADERBOARD_FILE) | |
df_sorted = df.sort_values(by="score", ascending=False) | |
st.subheader("Leaderboard") | |
st.dataframe(df_sorted) | |