SD_Hackathon / src /streamlit_app.py
com3dian's picture
Update src/streamlit_app.py
abed169 verified
import streamlit as st
import pandas as pd
import os
import datetime
import dill as pickle
import inspect
from google_sheet import *
from google_drive import upload_to_drive
st.title("πŸ† Hackathon Leaderboard")
# ========================
# Submission Form
# ========================
import uuid
uploaded_file = st.file_uploader("Upload your submission (.zip)", type=["zip"], key=str(uuid.uuid4()))
if uploaded_file and st.button("Submit"):
timestamp = datetime.datetime.now().isoformat()
submission_filename = f"{timestamp.replace(':', '_')}_{uploaded_file.name}"
submission_path = os.path.join("submissions", submission_filename)
os.makedirs("submissions", exist_ok=True)
# Save uploaded file
with open(submission_path, "wb") as f:
f.write(uploaded_file.read())
try:
drive_file_id = upload_to_drive(submission_path, submission_filename)
st.success(f"Uploaded to Google Drive βœ… [File ID: {drive_file_id}]")
except Exception as e:
st.warning(f"Failed to upload to Google Drive: {e}")
# ========================
# Always Show Leaderboard
# ========================
st.subheader("Leaderboard")
try:
df = fetch_leaderboard()
if not df.empty:
df_sorted = df.sort_values(by="score", ascending=False)
st.dataframe(df_sorted)
else:
st.info("No submissions yet.")
except Exception as e:
st.warning(f"Could not load leaderboard: {e}")