com3dian commited on
Commit
92b0129
Β·
verified Β·
1 Parent(s): c803d4b

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +26 -8
src/streamlit_app.py CHANGED
@@ -2,6 +2,8 @@ import streamlit as st
2
  import pandas as pd
3
  import os
4
  import datetime
 
 
5
 
6
  from google_sheet import *
7
 
@@ -11,27 +13,43 @@ st.title("πŸ† Hackathon Leaderboard")
11
  # Submission Form
12
  # ========================
13
 
14
- uploaded_file = st.file_uploader("Upload your solution (.py)", type=["py"])
 
 
 
 
 
 
15
 
16
  if uploaded_file and st.button("Submit"):
17
- # Generate unique filename based on timestamp
18
  timestamp = datetime.datetime.now().isoformat()
19
  submission_filename = f"{timestamp.replace(':', '_')}_{uploaded_file.name}"
20
  submission_path = os.path.join("submissions", submission_filename)
21
-
22
- # Ensure submissions folder exists
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
- # TODO: Add actual evaluation logic here
30
- score = 42 # Dummy score
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
- # Append to Google Sheet
33
  append_score(timestamp, score, submission_filename)
34
- st.success(f"Submission received! Score: {score}")
35
 
36
  # ========================
37
  # Always Show Leaderboard
 
2
  import pandas as pd
3
  import os
4
  import datetime
5
+ import pickle
6
+ import inspect
7
 
8
  from google_sheet import *
9
 
 
13
  # Submission Form
14
  # ========================
15
 
16
+ uploaded_file = st.file_uploader("Upload your model/class (.pkl)", type=["pkl"])
17
+
18
+ def is_valid_model(obj):
19
+ """
20
+ Check if the object is a class instance with a 'predict' method.
21
+ """
22
+ return hasattr(obj, 'get_team') and inspect.ismethod(getattr(obj, 'get_team', None)) or callable(getattr(obj, 'get_team', None))
23
 
24
  if uploaded_file and st.button("Submit"):
 
25
  timestamp = datetime.datetime.now().isoformat()
26
  submission_filename = f"{timestamp.replace(':', '_')}_{uploaded_file.name}"
27
  submission_path = os.path.join("submissions", submission_filename)
 
 
28
  os.makedirs("submissions", exist_ok=True)
29
 
30
  # Save uploaded file
31
  with open(submission_path, "wb") as f:
32
  f.write(uploaded_file.read())
33
 
34
+ # Load and evaluate model
35
+ try:
36
+ with open(submission_path, "rb") as f:
37
+ model = pickle.load(f)
38
+
39
+ if is_valid_model(model):
40
+ score = 100 # Example valid score
41
+ st.success("Valid model uploaded. βœ…")
42
+ else:
43
+ score = 0
44
+ st.error("Uploaded object does not implement a `predict` method. ❌")
45
+
46
+ except Exception as e:
47
+ score = 0
48
+ st.error(f"Failed to load or validate pickle file: {e}")
49
 
50
+ # Append result to leaderboard
51
  append_score(timestamp, score, submission_filename)
52
+ st.success(f"Submission received! Score: {score}; Team {team}")
53
 
54
  # ========================
55
  # Always Show Leaderboard