maitri01 commited on
Commit
f677e7a
·
verified ·
1 Parent(s): e647bdb

Create submission.py

Browse files
Files changed (1) hide show
  1. submission.py +76 -0
submission.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Submit your result to the hackathon server and print the score.
2
+
3
+ Before running, edit the two settings below:
4
+ API_KEY your team's API key (keep the double quotes)
5
+ SUBMISSION_FILE path to your .csv file, e.g. "submission.csv"
6
+ Then run:
7
+ python submission.py
8
+
9
+ The file must be a plain 18 x 18 matrix of 0 and 1 (no header, no ID column), symmetric, with 1 on the diagonal.
10
+ Wait 2 minutes between submissions.
11
+
12
+ Needs: pip install requests
13
+ """
14
+ import sys
15
+ from pathlib import Path
16
+
17
+ import requests
18
+
19
+ # ----------------------------------------------------------------------------- SETTINGS
20
+ API_KEY = "YOUR_API_KEY_HERE" # replace with your team's API key (keep the double quotes)
21
+ SUBMISSION_FILE = "/PATH/FILE.csv" # replace with the path to your results file
22
+ TASK_ID = "33-model-equality" # do not change
23
+ SERVER_URL = "http://34.147.229.55"
24
+ # -----------------------------------------------------------------------------
25
+
26
+ ALLOWED_SUFFIXES = (".csv",)
27
+
28
+
29
+ def main() -> int:
30
+ file = Path(SUBMISSION_FILE)
31
+
32
+ if API_KEY == "YOUR_API_KEY_HERE" or not API_KEY.strip():
33
+ print("Set API_KEY at the top of submission.py to your team's API key.", file=sys.stderr)
34
+ return 1
35
+ if not file.is_file():
36
+ print(f"File not found: {file}. Set SUBMISSION_FILE at the top of submission.py.", file=sys.stderr)
37
+ return 1
38
+ if file.suffix.lower() not in ALLOWED_SUFFIXES:
39
+ print(f"{TASK_ID} expects a {' or '.join(ALLOWED_SUFFIXES)} file, got {file.name}", file=sys.stderr)
40
+ return 1
41
+
42
+ print(f"Submitting {file.name} to {TASK_ID}. Scoring can take a few minutes...")
43
+ with file.open("rb") as f:
44
+ try:
45
+ reply = requests.post(
46
+ f"{SERVER_URL.rstrip('/')}/submit/{TASK_ID}",
47
+ headers={"X-API-Key": API_KEY},
48
+ files={"file": (file.name, f)},
49
+ timeout=(600, 600), # the server waits up to 500 s for the score
50
+ )
51
+ except requests.RequestException as exc:
52
+ print(f"Could not reach the server: {exc}", file=sys.stderr)
53
+ return 1
54
+
55
+ try:
56
+ body = reply.json()
57
+ except ValueError:
58
+ print(f"HTTP {reply.status_code}: {reply.text[:300]}", file=sys.stderr)
59
+ return 1
60
+
61
+ if reply.status_code != 200:
62
+ print(f"Rejected (HTTP {reply.status_code}): {body.get('detail', body)}", file=sys.stderr)
63
+ return 1
64
+ status = body.get("status")
65
+ if status == "success":
66
+ print(f"Score (public split): {body.get('score')}")
67
+ if "previous_best" in body:
68
+ print(f"Previous best: {body['previous_best']} (improved: {body.get('improved')})")
69
+ print(body.get("message", ""))
70
+ return 0
71
+ print(f"{status}: {body.get('message')}", file=sys.stderr)
72
+ return 1
73
+
74
+
75
+ if __name__ == "__main__":
76
+ sys.exit(main())