File size: 1,770 Bytes
1d9b43f 65a4620 1d9b43f 65a4620 1d9b43f 65a4620 1d9b43f 65a4620 1d9b43f 65a4620 1d9b43f 65a4620 1d9b43f 65a4620 1d9b43f 65a4620 1d9b43f 65a4620 1d9b43f 65a4620 1d9b43f 65a4620 |
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 |
import panel as pn
import pandas as pd
import os
import datetime
import io
from google_sheet import fetch_leaderboard
from google_drive import upload_to_drive
pn.extension()
# File upload widget
file_input = pn.widgets.FileInput(accept='.zip', multiple=False)
# Status message
status = pn.pane.Markdown("")
# Leaderboard display
leaderboard = pn.pane.DataFrame(pd.DataFrame(), width=600)
def submit_file(event):
if file_input.value is None:
status.object = "โ ๏ธ Please upload a .zip file before submitting."
return
# Save uploaded file
timestamp = datetime.datetime.now().isoformat().replace(":", "_")
filename = f"{timestamp}_{file_input.filename}"
submission_path = os.path.join("submissions", filename)
os.makedirs("submissions", exist_ok=True)
with open(submission_path, "wb") as f:
f.write(file_input.value)
try:
drive_file_id = upload_to_drive(submission_path, filename)
status.object = f"โ
Uploaded to Google Drive [File ID: {drive_file_id}]"
except Exception as e:
status.object = f"โ Failed to upload to Google Drive: {e}"
# Update leaderboard
try:
df = fetch_leaderboard()
if not df.empty:
df_sorted = df.sort_values(by="score", ascending=False)
leaderboard.object = df_sorted
else:
leaderboard.object = pd.DataFrame()
except Exception as e:
status.object += f"\nโ ๏ธ Could not load leaderboard: {e}"
submit_button = pn.widgets.Button(name="Submit", button_type="primary")
submit_button.on_click(submit_file)
# Layout
app = pn.Column(
"## ๐ Hackathon Leaderboard",
file_input,
submit_button,
status,
"### Leaderboard",
leaderboard
)
app.servable()
|