SD_Hackathon / src /streamlit_app.py
com3dian's picture
Update src/streamlit_app.py
bec9209 verified
raw
history blame
1.48 kB
import streamlit as st
import pandas as pd
import os
import datetime
import json
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from data_upload import *
st.title("πŸ† Hackathon Leaderboard")
# ========================
# Submission Form
# ========================
uploaded_file = st.file_uploader("Upload your solution (.py)", type=["py"])
if uploaded_file:
if st.button("Submit"):
# Generate unique filename based on timestamp
timestamp = datetime.datetime.now().isoformat()
submission_filename = f"{timestamp.replace(':', '_')}_{uploaded_file.name}"
submission_path = os.path.join("submissions", submission_filename)
# Ensure submissions folder exists
os.makedirs("submissions", exist_ok=True)
# Save uploaded file
with open(submission_path, "wb") as f:
f.write(uploaded_file.read())
# TODO: Add actual evaluation logic here
score = 42 # Dummy score
# Append to Google Sheet
append_score(timestamp, score, submission_filename)
st.success(f"Submission received! Score: {score}")
# ========================
# Show Leaderboard
# ========================
try:
df = fetch_leaderboard()
if not df.empty:
df_sorted = df.sort_values(by="score", ascending=False)
st.subheader("Leaderboard")
st.dataframe(df_sorted)
except Exception as e:
st.warning(f"Could not load leaderboard: {e}")