different submit function
Browse files
app.py
CHANGED
|
@@ -13,35 +13,6 @@ 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):
|
|
@@ -57,13 +28,8 @@ def make_submission(
|
|
| 57 |
path_obj = Path(file_path)
|
| 58 |
timestamp = datetime.utcnow().isoformat()
|
| 59 |
|
| 60 |
-
with (
|
| 61 |
-
path_obj.open("rb") as f_in,
|
| 62 |
-
tempfile.NamedTemporaryFile(delete=False, suffix=".json") as tmp_boundary,
|
| 63 |
-
):
|
| 64 |
file_content = f_in.read()
|
| 65 |
-
tmp_boundary.write(file_content)
|
| 66 |
-
tmp_boundary_path = Path(tmp_boundary.name)
|
| 67 |
|
| 68 |
# write to dataset
|
| 69 |
filename = f"{user_state}/{timestamp.replace(':', '-')}_{user_state}.json"
|
|
@@ -88,10 +54,8 @@ def make_submission(
|
|
| 88 |
)
|
| 89 |
Path(tmp_name).unlink()
|
| 90 |
|
| 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")
|
|
|
|
| 13 |
from datasets import load_dataset
|
| 14 |
import io
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
def make_submission(
|
| 17 |
submitted_file: BinaryIO,
|
| 18 |
user_state):
|
|
|
|
| 28 |
path_obj = Path(file_path)
|
| 29 |
timestamp = datetime.utcnow().isoformat()
|
| 30 |
|
| 31 |
+
with (path_obj.open("rb") as f_in):
|
|
|
|
|
|
|
|
|
|
| 32 |
file_content = f_in.read()
|
|
|
|
|
|
|
| 33 |
|
| 34 |
# write to dataset
|
| 35 |
filename = f"{user_state}/{timestamp.replace(':', '-')}_{user_state}.json"
|
|
|
|
| 54 |
)
|
| 55 |
Path(tmp_name).unlink()
|
| 56 |
|
|
|
|
|
|
|
| 57 |
return "✅ Your submission has been received! Sit tight and your scores will appear on the leaderboard shortly."
|
| 58 |
+
|
| 59 |
|
| 60 |
def get_leaderboard_table(assay: str | None = None):
|
| 61 |
# ds = load_dataset(results_repo, split='train', download_mode="force_redownload")
|