Spaces:
Sleeping
Sleeping
File size: 2,056 Bytes
d22a7f8 475174a 92b0129 d22a7f8 86c31d7 8fb7a79 bec9209 92b0129 8fb7a79 c803d4b d7cb7b3 c803d4b 475174a 92b0129 f35d78d 92b0129 f35d78d 92b0129 475174a 92b0129 c803d4b 92b0129 475174a bec9209 c803d4b bec9209 c803d4b bec9209 c803d4b bec9209 |
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
import streamlit as st
import pandas as pd
import os
import datetime
import pickle
import inspect
from google_sheet import *
st.title("π Hackathon Leaderboard")
# ========================
# Submission Form
# ========================
uploaded_file = st.file_uploader("Upload your model/class (.pkl)", type=["pkl"])
def is_valid_model(obj):
"""
Check if the object is a class instance with a 'predict' method.
"""
return hasattr(obj, 'get_team') and inspect.ismethod(getattr(obj, 'get_team', None)) or callable(getattr(obj, 'get_team', None))
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())
# Load and evaluate model
try:
with open(submission_path, "rb") as f:
model = pickle.load(f)
if is_valid_model(model):
team = model.get_team()
score = 100 # Example valid score
st.success("Valid model uploaded. β
")
else:
team = "fail"
score = 0
st.error("Uploaded object does not implement a `predict` method. β")
except Exception as e:
score = 0
st.error(f"Failed to load or validate pickle file: {e}")
# Append result to leaderboard
append_score(timestamp, score, submission_filename)
st.success(f"Submission received! Score: {score}; Team {team}")
# ========================
# 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}")
|