cgeorgiaw HF Staff commited on
Commit
956b725
·
1 Parent(s): abeb215

trying to write results

Browse files
Files changed (1) hide show
  1. app.py +23 -1
app.py CHANGED
@@ -16,6 +16,7 @@ TOKEN = os.environ.get("HF_TOKEN")
16
  CACHE_PATH=os.getenv("HF_HOME", ".")
17
  API = HfApi(token=TOKEN)
18
  submissions_repo = "cgeorgiaw/constellaration-submissions"
 
19
 
20
  def submit_boundary(
21
  problem_type: Literal["geometrical", "simple_to_build", "mhd_stable"],
@@ -40,6 +41,7 @@ def submit_boundary(
40
  # write to dataset
41
  filename = f"{problem_type}/{timestamp.replace(':', '-')}_{problem_type}.json"
42
  record = {
 
43
  "submission_time": timestamp,
44
  "problem_type": problem_type,
45
  "boundary_json": file_content.decode("utf-8"),
@@ -63,8 +65,8 @@ def submit_boundary(
63
  local_path = read_boundary(filename)
64
 
65
  try:
66
- # result = evaluate_problem(problem_type, str(tmp_boundary_path))
67
  result = evaluate_problem(problem_type, local_path)
 
68
  output = str(result)
69
  except Exception as e:
70
  output = f"Error during evaluation:\n{e}"
@@ -81,6 +83,26 @@ def read_boundary(filename):
81
  )
82
  return local_path
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  def gradio_interface() -> gr.Blocks:
85
  with gr.Blocks() as demo:
86
  gr.Markdown(
 
16
  CACHE_PATH=os.getenv("HF_HOME", ".")
17
  API = HfApi(token=TOKEN)
18
  submissions_repo = "cgeorgiaw/constellaration-submissions"
19
+ results_repo = "cgeorgiaw/constellaration-results"
20
 
21
  def submit_boundary(
22
  problem_type: Literal["geometrical", "simple_to_build", "mhd_stable"],
 
41
  # write to dataset
42
  filename = f"{problem_type}/{timestamp.replace(':', '-')}_{problem_type}.json"
43
  record = {
44
+ "submission_filename": filename,
45
  "submission_time": timestamp,
46
  "problem_type": problem_type,
47
  "boundary_json": file_content.decode("utf-8"),
 
65
  local_path = read_boundary(filename)
66
 
67
  try:
 
68
  result = evaluate_problem(problem_type, local_path)
69
+ write_results(record, result)
70
  output = str(result)
71
  except Exception as e:
72
  output = f"Error during evaluation:\n{e}"
 
83
  )
84
  return local_path
85
 
86
+ def write_results(record, result):
87
+ record.update(result)
88
+ record['result_filename'] = record['submission_filename'].strip('.json') + '_results.json'
89
+ with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as tmp:
90
+ json.dump(record, tmp, indent=2)
91
+ tmp.flush()
92
+ tmp_name = tmp.name
93
+
94
+ API.upload_file(
95
+ path_or_fileobj=tmp_name,
96
+ path_in_repo=record['result_filename'],
97
+ repo_id=results_repo,
98
+ repo_type="dataset",
99
+ commit_message=f"Add result data for {record['result_filename']}"
100
+ )
101
+
102
+ pathlib.Path(tmp_name).unlink()
103
+ return
104
+
105
+
106
  def gradio_interface() -> gr.Blocks:
107
  with gr.Blocks() as demo:
108
  gr.Markdown(