File size: 2,641 Bytes
db4f343 e9d1eee db4f343 e9d1eee db4f343 e9d1eee db4f343 e9d1eee db4f343 cd176ed f98657b db4f343 e9d1eee db4f343 e9d1eee c05e0a4 f98657b c05e0a4 e9d1eee db4f343 e9d1eee e7c0508 db4f343 e7c0508 db4f343 e9d1eee db4f343 e9d1eee db4f343 e9d1eee db4f343 fd7ccb5 db4f343 e9d1eee ab2c92a |
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
import os
import tempfile
import panel as pn
import pandas as pd
from google_sheet import fetch_leaderboard
from google_drive import upload_to_drive
pn.extension(design="bootstrap", sizing_mode="stretch_width")
# Widgets
file_input = pn.widgets.FileInput(accept='.zip', multiple=False)
submit_button = pn.widgets.Button(name="π€ Submit", button_type="primary")
status = pn.pane.Alert("", alert_type="info", visible=False)
leaderboard = pn.pane.DataFrame(pd.DataFrame(), width=800, height=400, index=False)
# Temp dir
temp_dir = tempfile.gettempdir()
# --- Submission logic ---
def submit_file(event):
if file_input.value is None:
status.object = "β οΈ Please upload a .zip file before submitting."
status.alert_type = "warning"
status.visible = True
return
try:
filename = file_input.filename
submission_path = os.path.join(temp_dir, filename)
with open(submission_path, "wb") as f:
f.write(file_input.value)
drive_file_id = upload_to_drive(submission_path, filename)
status.object = f"β
Uploaded to Google Drive\n**File ID**: `{drive_file_id}`"
status.alert_type = "success"
status.visible = True
except Exception as e:
import traceback
status.object += f"\nβ οΈ Could not load leaderboard:\n```\n{traceback.format_exc()}\n```"
status.alert_type = "warning"
status.visible = True
# status.object = f"β Failed to upload: {e}"
# status.alert_type = "danger"
# status.visible = True
return
# Refresh leaderboard
update_leaderboard()
submit_button.on_click(submit_file)
# --- Leaderboard logic ---
def update_leaderboard():
try:
df = fetch_leaderboard()
if not df.empty:
leaderboard.object = df.sort_values(by="score", ascending=False)
else:
leaderboard.object = pd.DataFrame()
except Exception as e:
status.object = f"β οΈ Could not load leaderboard: {e}"
status.alert_type = "warning"
status.visible = True
# Initial load
update_leaderboard()
# --- Layout ---
app = pn.template.BootstrapTemplate(
title="π Hackathon Leaderboard",
sidebar=[
pn.pane.Markdown("### π Upload Your Submission (.zip)"),
file_input,
submit_button,
status,
],
main=[
pn.pane.Markdown("## π₯ Live Leaderboard"),
pn.pane.Markdown("βΉοΈ *Note: To see the most up-to-date results, please refresh the web page.*", styles={'color': 'gray', 'font-style': 'italic'}),
leaderboard
]
)
app.servable()
|