import gradio as gr import pandas as pd import os import datetime from google_sheet import fetch_leaderboard from google_drive import upload_to_drive os.makedirs("submissions", exist_ok=True) def get_leaderboard_html(): try: df = fetch_leaderboard() if df.empty: return "

No submissions yet.

" df_sorted = df.sort_values(by="score", ascending=False) return df_sorted.to_html(index=False) except Exception as e: return f"

Could not load leaderboard: {e}

" def handle_submission(file): if file is None: return "❌ No file uploaded.", "

No leaderboard to show.

" timestamp = datetime.datetime.now().isoformat().replace(":", "_") submission_filename = f"{timestamp}_{file.name}" submission_path = os.path.join("submissions", submission_filename) with open(submission_path, "wb") as f: f.write(file.read()) try: drive_file_id = upload_to_drive(submission_path, submission_filename) status = f"✅ Uploaded to Google Drive [File ID: {drive_file_id}]" except Exception as e: status = f"⚠️ Failed to upload to Google Drive: {e}" leaderboard_html = get_leaderboard_html() return status, leaderboard_html with gr.Blocks(title="🏆 Hackathon Leaderboard") as demo: gr.Markdown("## 🏆 Hackathon Leaderboard") with gr.Row(): file_input = gr.File(label="Upload your submission (.zip)", file_types=[".zip"]) submit_btn = gr.Button("Submit") status_output = gr.Markdown() leaderboard_output = gr.HTML(get_leaderboard_html()) submit_btn.click( fn=handle_submission, inputs=file_input, outputs=[status_output, leaderboard_output] ) demo.launch(share=True)