cgeorgiaw HF Staff commited on
Commit
638faee
·
1 Parent(s): 74b87cd

different submit function

Browse files
Files changed (1) hide show
  1. app.py +32 -1
app.py CHANGED
@@ -11,7 +11,37 @@ from typing import BinaryIO, Literal
11
  from datetime import datetime
12
  import tempfile
13
  from datasets import load_dataset
 
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  def make_submission(
16
  submitted_file: BinaryIO,
17
  user_state):
@@ -61,7 +91,8 @@ def make_submission(
61
  tmp_boundary_path.unlink()
62
 
63
  return "✅ Your submission has been received! Sit tight and your scores will appear on the leaderboard shortly."
64
-
 
65
  def get_leaderboard_table(assay: str | None = None):
66
  # ds = load_dataset(results_repo, split='train', download_mode="force_redownload")
67
  # full_df = pd.DataFrame(ds)
 
11
  from datetime import datetime
12
  import tempfile
13
  from datasets import load_dataset
14
+ import io
15
 
16
+ def make_submission(submitted_file: BinaryIO, user_state):
17
+ if not user_state:
18
+ raise gr.Error("You must submit your username to submit a file.")
19
+
20
+ csv_content = submitted_file.read().decode("utf-8") # decode bytes to string
21
+
22
+ timestamp = datetime.utcnow().isoformat()
23
+ filename = f"{user_state}/{timestamp.replace(':', '-')}_{user_state}.json"
24
+
25
+ record = {
26
+ "submission_filename": filename,
27
+ "submission_time": timestamp,
28
+ "csv_content": csv_content, # keep as string for JSON
29
+ "evaluated": False,
30
+ "user": user_state,
31
+ }
32
+
33
+ json_bytes = json.dumps(record, indent=2).encode("utf-8")
34
+ json_file = io.BytesIO(json_bytes)
35
+ json_file.name = filename
36
+
37
+ API.upload_file(
38
+ path_or_fileobj=json_file,
39
+ path_in_repo=filename,
40
+ repo_id=submissions_repo,
41
+ repo_type="dataset",
42
+ commit_message=f"Add submission for {user_state} at {timestamp}"
43
+ )
44
+ '''
45
  def make_submission(
46
  submitted_file: BinaryIO,
47
  user_state):
 
91
  tmp_boundary_path.unlink()
92
 
93
  return "✅ Your submission has been received! Sit tight and your scores will appear on the leaderboard shortly."
94
+ '''
95
+
96
  def get_leaderboard_table(assay: str | None = None):
97
  # ds = load_dataset(results_repo, split='train', download_mode="force_redownload")
98
  # full_df = pd.DataFrame(ds)