Spaces:
Sleeping
Sleeping
File size: 1,774 Bytes
326967b 475174a d22a7f8 10f2e01 f970fd2 8fb7a79 326967b 8fb7a79 326967b d8e6110 326967b d8e6110 e31cd27 326967b e31cd27 326967b 10f2e01 8542abb 326967b 8542abb 326967b 10f2e01 326967b e31cd27 326967b 10f2e01 326967b 10f2e01 326967b |
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 |
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 "<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>"
def handle_submission(file):
if file is None:
return "β No file uploaded.", "<p>No leaderboard to show.</p>"
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)
|