cgeorgiaw HF Staff commited on
Commit
0c144dc
·
1 Parent(s): 8ba1e6e

trying to write to dataset

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -27,11 +27,11 @@ def submit_boundary(
27
 
28
  with (
29
  path_obj.open("rb") as f_in,
30
- tempfile.NamedTemporaryFile(delete=False, suffix=".json") as tmp,
31
  ):
32
  file_content = f_in.read()
33
- tmp.write(file_content)
34
- tmp_path = pathlib.Path(tmp.name)
35
 
36
  # write to dataset
37
  filename = f"data/{timestamp.replace(':', '-')}_{problem_type}.json"
@@ -40,23 +40,28 @@ def submit_boundary(
40
  "problem_type": problem_type,
41
  "boundary_json": file_content.decode("utf-8"), # Or store file path or URL
42
  }
43
- json.dump(record, tmp, indent=2)
44
- tmp.flush()
 
 
 
45
  upload_file(
46
- path_or_fileobj=f_in,
47
  path_in_repo=filename,
48
  repo_id=repo_id,
49
  repo_type="dataset",
50
  commit_message=f"Add submission for {problem_type} at {timestamp}"
51
  )
 
52
 
 
53
  try:
54
- result = evaluate_problem(problem_type, str(tmp_path))
55
  output = str(result)
56
  except Exception as e:
57
  output = f"Error during evaluation:\n{e}"
58
  finally:
59
- tmp_path.unlink()
60
 
61
  return output
62
 
 
27
 
28
  with (
29
  path_obj.open("rb") as f_in,
30
+ tempfile.NamedTemporaryFile(delete=False, suffix=".json") as tmp_boundary,
31
  ):
32
  file_content = f_in.read()
33
+ tmp_boundary.write(file_content)
34
+ tmp_boundary_path = pathlib.Path(tmp_boundary.name)
35
 
36
  # write to dataset
37
  filename = f"data/{timestamp.replace(':', '-')}_{problem_type}.json"
 
40
  "problem_type": problem_type,
41
  "boundary_json": file_content.decode("utf-8"), # Or store file path or URL
42
  }
43
+ with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as tmp:
44
+ json.dump(record, tmp, indent=2)
45
+ tmp.flush()
46
+ tmp_name = tmp.name
47
+
48
  upload_file(
49
+ path_or_fileobj=tmp_name,
50
  path_in_repo=filename,
51
  repo_id=repo_id,
52
  repo_type="dataset",
53
  commit_message=f"Add submission for {problem_type} at {timestamp}"
54
  )
55
+ pathlib.Path(tmp_name).unlink()
56
 
57
+ # then do eval
58
  try:
59
+ result = evaluate_problem(problem_type, str(tmp_boundary_path))
60
  output = str(result)
61
  except Exception as e:
62
  output = f"Error during evaluation:\n{e}"
63
  finally:
64
+ tmp_boundary_path.unlink()
65
 
66
  return output
67