Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +11 -22
src/streamlit_app.py
CHANGED
|
@@ -6,15 +6,22 @@ import datetime
|
|
| 6 |
from google_sheet import fetch_leaderboard
|
| 7 |
from google_drive import upload_to_drive
|
| 8 |
|
| 9 |
-
# Ensure the submissions folder exists
|
| 10 |
os.makedirs("submissions", exist_ok=True)
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
def handle_submission(file):
|
| 14 |
if file is None:
|
| 15 |
return "β No file uploaded.", "<p>No leaderboard to show.</p>"
|
| 16 |
|
| 17 |
-
# Save file
|
| 18 |
timestamp = datetime.datetime.now().isoformat().replace(":", "_")
|
| 19 |
submission_filename = f"{timestamp}_{file.name}"
|
| 20 |
submission_path = os.path.join("submissions", submission_filename)
|
|
@@ -31,21 +38,6 @@ def handle_submission(file):
|
|
| 31 |
leaderboard_html = get_leaderboard_html()
|
| 32 |
return status, leaderboard_html
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
# --- Leaderboard Logic ---
|
| 37 |
-
def get_leaderboard_html():
|
| 38 |
-
try:
|
| 39 |
-
df = fetch_leaderboard()
|
| 40 |
-
if df.empty:
|
| 41 |
-
return "<p>No submissions yet.</p>"
|
| 42 |
-
df_sorted = df.sort_values(by="score", ascending=False)
|
| 43 |
-
return df_sorted.to_html(index=False)
|
| 44 |
-
except Exception as e:
|
| 45 |
-
return f"<p>Could not load leaderboard: {e}</p>"
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
# --- Gradio Interface ---
|
| 49 |
with gr.Blocks(title="π Hackathon Leaderboard") as demo:
|
| 50 |
gr.Markdown("## π Hackathon Leaderboard")
|
| 51 |
|
|
@@ -56,11 +48,8 @@ with gr.Blocks(title="π Hackathon Leaderboard") as demo:
|
|
| 56 |
status_output = gr.Markdown()
|
| 57 |
leaderboard_output = gr.HTML(get_leaderboard_html())
|
| 58 |
|
| 59 |
-
def submit_action(file):
|
| 60 |
-
return handle_submission(file)
|
| 61 |
-
|
| 62 |
submit_btn.click(
|
| 63 |
-
fn=
|
| 64 |
inputs=file_input,
|
| 65 |
outputs=[status_output, leaderboard_output]
|
| 66 |
)
|
|
|
|
| 6 |
from google_sheet import fetch_leaderboard
|
| 7 |
from google_drive import upload_to_drive
|
| 8 |
|
|
|
|
| 9 |
os.makedirs("submissions", exist_ok=True)
|
| 10 |
|
| 11 |
+
def get_leaderboard_html():
|
| 12 |
+
try:
|
| 13 |
+
df = fetch_leaderboard()
|
| 14 |
+
if df.empty:
|
| 15 |
+
return "<p>No submissions yet.</p>"
|
| 16 |
+
df_sorted = df.sort_values(by="score", ascending=False)
|
| 17 |
+
return df_sorted.to_html(index=False)
|
| 18 |
+
except Exception as e:
|
| 19 |
+
return f"<p>Could not load leaderboard: {e}</p>"
|
| 20 |
+
|
| 21 |
def handle_submission(file):
|
| 22 |
if file is None:
|
| 23 |
return "β No file uploaded.", "<p>No leaderboard to show.</p>"
|
| 24 |
|
|
|
|
| 25 |
timestamp = datetime.datetime.now().isoformat().replace(":", "_")
|
| 26 |
submission_filename = f"{timestamp}_{file.name}"
|
| 27 |
submission_path = os.path.join("submissions", submission_filename)
|
|
|
|
| 38 |
leaderboard_html = get_leaderboard_html()
|
| 39 |
return status, leaderboard_html
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
with gr.Blocks(title="π Hackathon Leaderboard") as demo:
|
| 42 |
gr.Markdown("## π Hackathon Leaderboard")
|
| 43 |
|
|
|
|
| 48 |
status_output = gr.Markdown()
|
| 49 |
leaderboard_output = gr.HTML(get_leaderboard_html())
|
| 50 |
|
|
|
|
|
|
|
|
|
|
| 51 |
submit_btn.click(
|
| 52 |
+
fn=handle_submission,
|
| 53 |
inputs=file_input,
|
| 54 |
outputs=[status_output, leaderboard_output]
|
| 55 |
)
|