Spaces:
Running
on
Zero
Running
on
Zero
root
commited on
Commit
·
c597a5b
1
Parent(s):
7c802f7
support custom test case
Browse files
app.py
CHANGED
@@ -21,15 +21,13 @@ from multiprocessing import Process, Queue
|
|
21 |
import io
|
22 |
import sys
|
23 |
|
24 |
-
def unsafe_execute(
|
25 |
check_program = (
|
26 |
-
|
27 |
+ completion
|
28 |
-
+
|
29 |
-
+ "\n"
|
30 |
-
+
|
31 |
-
+ "\n"
|
32 |
-
+ f"check({problem['entry_point']})"
|
33 |
)
|
34 |
|
35 |
# 重定向标准输出和标准错误
|
@@ -433,16 +431,11 @@ def get_example_input():
|
|
433 |
test_case = problem['test']
|
434 |
test_case = test_case.replace('def check(candidate):', 'def run_test():')
|
435 |
test_case = test_case.replace('candidate', problem['entry_point'])
|
|
|
436 |
return prefix, '', suffix, test_case, task_id, ''
|
437 |
|
438 |
-
def check_result(
|
439 |
-
|
440 |
-
problem = problems[task_id]
|
441 |
-
print('run check')
|
442 |
-
print(task_id)
|
443 |
-
print(completion)
|
444 |
-
# 这里假设 `unsafe_execute` 是一个可以执行代码并返回结果的函数
|
445 |
-
result = unsafe_execute(problem, completion)
|
446 |
return result
|
447 |
|
448 |
|
@@ -463,8 +456,8 @@ def create_chatbot_demo():
|
|
463 |
with gr.Row():
|
464 |
sample_btn = gr.Button("Example Prompt")
|
465 |
generate_btn = gr.Button("Generate", variant="primary")
|
466 |
-
clear_btn = gr.Button("Clear")
|
467 |
check_btn = gr.Button("Run test case")
|
|
|
468 |
|
469 |
with gr.Row():
|
470 |
with gr.Column():
|
@@ -620,7 +613,7 @@ def create_chatbot_demo():
|
|
620 |
check_btn.click(
|
621 |
fn=check_result,
|
622 |
inputs=[task_id_input, output_vis],
|
623 |
-
outputs=[
|
624 |
queue=False
|
625 |
)
|
626 |
|
|
|
21 |
import io
|
22 |
import sys
|
23 |
|
24 |
+
def unsafe_execute(prompt, completion, suffix, test_case, timeout=3):
|
25 |
check_program = (
|
26 |
+
prompt
|
27 |
+ completion
|
28 |
+
+ suffix
|
29 |
+
+ "\n\n"
|
30 |
+
+ test_case
|
|
|
|
|
31 |
)
|
32 |
|
33 |
# 重定向标准输出和标准错误
|
|
|
431 |
test_case = problem['test']
|
432 |
test_case = test_case.replace('def check(candidate):', 'def run_test():')
|
433 |
test_case = test_case.replace('candidate', problem['entry_point'])
|
434 |
+
test_case = test_case + '\n\n\nrun_test()'
|
435 |
return prefix, '', suffix, test_case, task_id, ''
|
436 |
|
437 |
+
def check_result(prompt, completion, suffix, test_case):
|
438 |
+
result = unsafe_execute(prompt, completion, suffix, test_case)
|
|
|
|
|
|
|
|
|
|
|
|
|
439 |
return result
|
440 |
|
441 |
|
|
|
456 |
with gr.Row():
|
457 |
sample_btn = gr.Button("Example Prompt")
|
458 |
generate_btn = gr.Button("Generate", variant="primary")
|
|
|
459 |
check_btn = gr.Button("Run test case")
|
460 |
+
clear_btn = gr.Button("Clear")
|
461 |
|
462 |
with gr.Row():
|
463 |
with gr.Column():
|
|
|
613 |
check_btn.click(
|
614 |
fn=check_result,
|
615 |
inputs=[task_id_input, output_vis],
|
616 |
+
outputs=[prefix_input, output_vis, suffix_input, test_case_input]
|
617 |
queue=False
|
618 |
)
|
619 |
|