朱东升 commited on
Commit
a2bac48
·
1 Parent(s): 2a47279

requirements update9

Browse files
Files changed (1) hide show
  1. app.py +12 -12
app.py CHANGED
@@ -44,7 +44,7 @@ def evaluate(input_data):
44
  results = []
45
  for comp in completions:
46
  code = input_data.get('prompt') + comp + '\n' + input_data.get('tests')
47
- print(code)
48
  result = evaluate_code(code, language)
49
  results.append(result)
50
 
@@ -75,20 +75,20 @@ def evaluate_code(code, language):
75
  module_name = f"src.eval_{language.lower()}"
76
  module = importlib.import_module(module_name)
77
 
78
- # 创建临时文件存储代码
79
- temp_dir = Path("temp")
80
- temp_dir.mkdir(exist_ok=True)
81
- temp_file = temp_dir / f"temp.{language}"
82
-
83
- with open(temp_file, "w") as f:
84
- f.write(code)
85
-
86
  # 调用对应语言的评估函数
87
- result = module.eval_script(temp_file)
88
 
89
  # 清理临时文件
90
- if temp_file.exists():
91
- temp_file.unlink()
92
 
93
  return result
94
 
 
44
  results = []
45
  for comp in completions:
46
  code = input_data.get('prompt') + comp + '\n' + input_data.get('tests')
47
+ print(f'Code waiting for testing: {code}')
48
  result = evaluate_code(code, language)
49
  results.append(result)
50
 
 
75
  module_name = f"src.eval_{language.lower()}"
76
  module = importlib.import_module(module_name)
77
 
78
+ # 使用系统临时目录而不是固定的temp目录
79
+ import tempfile
80
+
81
+ # 创建临时文件
82
+ with tempfile.NamedTemporaryFile(suffix=f".{language}", delete=False) as temp_file:
83
+ temp_file_path = temp_file.name
84
+ temp_file.write(code.encode('utf-8'))
85
+
86
  # 调用对应语言的评估函数
87
+ result = module.eval_script(temp_file_path)
88
 
89
  # 清理临时文件
90
+ if os.path.exists(temp_file_path):
91
+ os.unlink(temp_file_path)
92
 
93
  return result
94