| | 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") |
| |
|
| | |
| | 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 = tempfile.gettempdir() |
| |
|
| | |
| | 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 |
| | |
| | |
| | |
| | return |
| |
|
| | |
| | update_leaderboard() |
| |
|
| | submit_button.on_click(submit_file) |
| |
|
| | |
| | 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 |
| |
|
| | |
| | update_leaderboard() |
| |
|
| | |
| | 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() |
| |
|