com3dian commited on
Commit
43bd9c2
Β·
verified Β·
1 Parent(s): 5c89c3c

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +29 -21
src/streamlit_app.py CHANGED
@@ -1,41 +1,49 @@
1
  import streamlit as st
2
  import pandas as pd
3
- from evaluation import evaluate_submission
4
  import os
5
  import datetime
6
- import sys
7
 
8
- # Make sure current directory includes parent of 'source'
9
- sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
10
-
11
- LEADERBOARD_FILE = os.path.join(os.path.dirname(__file__), "..", "leaderboard.csv")
12
 
13
  st.title("πŸ† Hackathon Leaderboard")
14
 
15
- uploaded_file = st.file_uploader("Upload your submission (.py)")
 
 
16
 
17
- if uploaded_file:
18
- temp_path = os.path.join(os.path.dirname(__file__), "submission_temp.py")
19
- with open(temp_path, "wb") as f:
20
- f.write(uploaded_file.read())
 
 
 
21
 
22
- try:
23
- score = evaluate_submission(temp_path) # Implement this
24
- timestamp = datetime.datetime.now().isoformat()
25
- entry = {"filename": uploaded_file.name, "score": score, "timestamp": timestamp}
26
 
27
- # Save to leaderboard
 
 
 
 
 
 
 
 
 
28
  if os.path.exists(LEADERBOARD_FILE):
29
  df = pd.read_csv(LEADERBOARD_FILE)
30
  df = pd.concat([df, pd.DataFrame([entry])], ignore_index=True)
31
  else:
32
  df = pd.DataFrame([entry])
33
- except Exception as e:
34
- st.error(f"Error: {e}")
 
35
 
36
  # Show leaderboard
37
  if os.path.exists(LEADERBOARD_FILE):
38
  df = pd.read_csv(LEADERBOARD_FILE)
39
- df = df.sort_values(by="score", ascending=False)
40
- st.subheader("πŸ… Leaderboard")
41
- st.dataframe(df)
 
1
  import streamlit as st
2
  import pandas as pd
 
3
  import os
4
  import datetime
 
5
 
6
+ LEADERBOARD_FILE = "leaderboard.csv"
 
 
 
7
 
8
  st.title("πŸ† Hackathon Leaderboard")
9
 
10
+ # User submission
11
+ uploaded_file = st.file_uploader("Upload your solution (.py)", type=["py"])
12
+ username = st.text_input("Enter your team name")
13
 
14
+ if uploaded_file and username:
15
+ if st.button("Submit"):
16
+ # Save uploaded file (optional)
17
+ submission_path = f"submissions/{username}_{datetime.datetime.now().timestamp()}.py"
18
+ os.makedirs("submissions", exist_ok=True)
19
+ with open(submission_path, "wb") as f:
20
+ f.write(uploaded_file.read())
21
 
22
+ # TODO: Add your custom evaluation logic here
23
+ score = 42 # Dummy score
 
 
24
 
25
+ # Log entry
26
+ timestamp = datetime.datetime.now().isoformat()
27
+ entry = {
28
+ "username": username,
29
+ "timestamp": timestamp,
30
+ "score": score,
31
+ "file": os.path.basename(submission_path),
32
+ }
33
+
34
+ # Append to CSV
35
  if os.path.exists(LEADERBOARD_FILE):
36
  df = pd.read_csv(LEADERBOARD_FILE)
37
  df = pd.concat([df, pd.DataFrame([entry])], ignore_index=True)
38
  else:
39
  df = pd.DataFrame([entry])
40
+
41
+ df.to_csv(LEADERBOARD_FILE, index=False)
42
+ st.success(f"Submission received! Score: {score}")
43
 
44
  # Show leaderboard
45
  if os.path.exists(LEADERBOARD_FILE):
46
  df = pd.read_csv(LEADERBOARD_FILE)
47
+ df_sorted = df.sort_values(by="score", ascending=False)
48
+ st.subheader("Leaderboard")
49
+ st.dataframe(df_sorted)