Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +31 -40
src/streamlit_app.py
CHANGED
@@ -1,57 +1,48 @@
|
|
1 |
-
import
|
2 |
import pandas as pd
|
3 |
import os
|
4 |
import datetime
|
|
|
|
|
5 |
|
6 |
-
from google_sheet import
|
7 |
from google_drive import upload_to_drive
|
8 |
|
9 |
-
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
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 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
timestamp = datetime.datetime.now().isoformat().replace(":", "_")
|
26 |
-
submission_filename = f"{timestamp}_{file.name}"
|
27 |
submission_path = os.path.join("submissions", submission_filename)
|
|
|
28 |
|
|
|
29 |
with open(submission_path, "wb") as f:
|
30 |
-
f.write(
|
31 |
|
32 |
try:
|
33 |
drive_file_id = upload_to_drive(submission_path, submission_filename)
|
34 |
-
|
35 |
except Exception as e:
|
36 |
-
|
37 |
-
|
38 |
-
leaderboard_html = get_leaderboard_html()
|
39 |
-
return status, leaderboard_html
|
40 |
|
41 |
-
|
42 |
-
|
|
|
|
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
inputs=file_input,
|
54 |
-
outputs=[status_output, leaderboard_output]
|
55 |
-
)
|
56 |
-
|
57 |
-
demo.launch(share=True)
|
|
|
1 |
+
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import os
|
4 |
import datetime
|
5 |
+
import dill as pickle
|
6 |
+
import inspect
|
7 |
|
8 |
+
from google_sheet import *
|
9 |
from google_drive import upload_to_drive
|
10 |
|
11 |
+
st.title("π Hackathon Leaderboard")
|
12 |
|
13 |
+
# ========================
|
14 |
+
# Submission Form
|
15 |
+
# ========================
|
16 |
+
import uuid
|
17 |
+
uploaded_file = st.file_uploader("Upload your submission (.zip)", type=["zip"], key=str(uuid.uuid4()))
|
|
|
|
|
|
|
|
|
18 |
|
19 |
+
if uploaded_file and st.button("Submit"):
|
20 |
+
timestamp = datetime.datetime.now().isoformat()
|
21 |
+
submission_filename = f"{timestamp.replace(':', '_')}_{uploaded_file.name}"
|
|
|
|
|
|
|
22 |
submission_path = os.path.join("submissions", submission_filename)
|
23 |
+
os.makedirs("submissions", exist_ok=True)
|
24 |
|
25 |
+
# Save uploaded file
|
26 |
with open(submission_path, "wb") as f:
|
27 |
+
f.write(uploaded_file.read())
|
28 |
|
29 |
try:
|
30 |
drive_file_id = upload_to_drive(submission_path, submission_filename)
|
31 |
+
st.success(f"Uploaded to Google Drive β
[File ID: {drive_file_id}]")
|
32 |
except Exception as e:
|
33 |
+
st.warning(f"Failed to upload to Google Drive: {e}")
|
|
|
|
|
|
|
34 |
|
35 |
+
# ========================
|
36 |
+
# Always Show Leaderboard
|
37 |
+
# ========================
|
38 |
+
st.subheader("Leaderboard")
|
39 |
|
40 |
+
try:
|
41 |
+
df = fetch_leaderboard()
|
42 |
+
if not df.empty:
|
43 |
+
df_sorted = df.sort_values(by="score", ascending=False)
|
44 |
+
st.dataframe(df_sorted)
|
45 |
+
else:
|
46 |
+
st.info("No submissions yet.")
|
47 |
+
except Exception as e:
|
48 |
+
st.warning(f"Could not load leaderboard: {e}")
|
|
|
|
|
|
|
|
|
|