File size: 1,980 Bytes
10f2e01
475174a
 
 
d22a7f8
10f2e01
f970fd2
8fb7a79
10f2e01
 
8fb7a79
10f2e01
 
 
 
bec9209
10f2e01
 
 
d8e6110
 
10f2e01
d8e6110
10f2e01
d8e6110
 
 
10f2e01
d8e6110
10f2e01
 
 
 
d8e6110
 
10f2e01
 
 
 
 
 
d8e6110
10f2e01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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

# Ensure the submissions folder exists
os.makedirs("submissions", exist_ok=True)

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

    # Generate timestamped filename
    timestamp = datetime.datetime.now().isoformat().replace(":", "_")
    submission_filename = f"{timestamp}_{file.name}"
    submission_path = os.path.join("submissions", submission_filename)

    # Save file
    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}"

    # Return status and updated leaderboard
    return status, get_leaderboard_html()


# --- Leaderboard Logic ---
def get_leaderboard_html():
    try:
        df = fetch_leaderboard()
        if df.empty:
            return "<p>No submissions yet.</p>"
        df_sorted = df.sort_values(by="score", ascending=False)
        return df_sorted.to_html(index=False)
    except Exception as e:
        return f"<p>Could not load leaderboard: {e}</p>"


# --- Gradio Interface ---
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())

    def submit_action(file):
        return handle_submission(file)

    submit_btn.click(
        fn=submit_action,
        inputs=file_input,
        outputs=[status_output, leaderboard_output]
    )

demo.launch()