Spaces:
Running
on
Zero
Running
on
Zero
root
commited on
Commit
·
929e531
1
Parent(s):
15b0565
update
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
-
#
|
2 |
-
|
3 |
import torch
|
4 |
import numpy as np
|
5 |
import gradio as gr
|
@@ -431,7 +431,7 @@ def get_example_input():
|
|
431 |
problem = problems[task_id]
|
432 |
prefix, suffix = problem['prompt'], problem['suffix']
|
433 |
test_case = problem['test']
|
434 |
-
return prefix, suffix, test_case, task_id
|
435 |
|
436 |
def check_result(task_id, completion):
|
437 |
# 从数据集中读取问题
|
@@ -458,55 +458,57 @@ def create_chatbot_demo():
|
|
458 |
"[[Blog](https://hkunlp.github.io/blog/2025/dreamon/)]"
|
459 |
)
|
460 |
|
461 |
-
with gr.
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
474 |
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
placeholder="Task ID will be stored here...",
|
493 |
-
visible=False
|
494 |
-
)
|
495 |
-
|
496 |
-
# Result of execution
|
497 |
-
result_output = gr.Textbox(
|
498 |
-
label="Result of Execution",
|
499 |
-
placeholder="Execution result will be shown here...",
|
500 |
-
lines=2
|
501 |
-
)
|
502 |
-
|
503 |
-
with gr.Row():
|
504 |
-
sample_btn = gr.Button("Example Prompt")
|
505 |
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
|
511 |
# Generation Settings
|
512 |
with gr.Accordion("Generation Settings"):
|
@@ -622,7 +624,7 @@ def create_chatbot_demo():
|
|
622 |
|
623 |
sample_btn.click(
|
624 |
fn=get_example_input,
|
625 |
-
outputs=[prefix_input, suffix_input, test_case_input, task_id_input],
|
626 |
queue=False
|
627 |
)
|
628 |
return demo
|
|
|
1 |
+
# dreamon_app.py
|
2 |
+
## this app is built based on https://huggingface.co/spaces/multimodalart/Dream/blob/main/app.py
|
3 |
import torch
|
4 |
import numpy as np
|
5 |
import gradio as gr
|
|
|
431 |
problem = problems[task_id]
|
432 |
prefix, suffix = problem['prompt'], problem['suffix']
|
433 |
test_case = problem['test']
|
434 |
+
return prefix, '', suffix, test_case, task_id, ''
|
435 |
|
436 |
def check_result(task_id, completion):
|
437 |
# 从数据集中读取问题
|
|
|
458 |
"[[Blog](https://hkunlp.github.io/blog/2025/dreamon/)]"
|
459 |
)
|
460 |
|
461 |
+
with gr.Row():
|
462 |
+
with gr.Column():
|
463 |
+
# Prefix input
|
464 |
+
prefix_input = gr.Textbox(
|
465 |
+
label="Prefix Text",
|
466 |
+
placeholder="Enter the beginning of your text...",
|
467 |
+
lines=2
|
468 |
+
)
|
469 |
+
|
470 |
+
# Middle generation/visualization area
|
471 |
+
output_vis = gr.Textbox(
|
472 |
+
label="Generated Text (Middle)",
|
473 |
+
lines=2
|
474 |
+
)
|
475 |
+
|
476 |
+
# Suffix input
|
477 |
+
suffix_input = gr.Textbox(
|
478 |
+
label="Suffix Text",
|
479 |
+
placeholder="Enter the end of your text...",
|
480 |
+
lines=2
|
481 |
+
)
|
482 |
+
|
483 |
+
# Hidden Task ID input
|
484 |
+
task_id_input = gr.Textbox(
|
485 |
+
label="Task ID",
|
486 |
+
placeholder="Task ID will be stored here...",
|
487 |
+
visible=False
|
488 |
+
)
|
489 |
|
490 |
+
with gr.Column():
|
491 |
+
# Test Case input
|
492 |
+
test_case_input = gr.Textbox(
|
493 |
+
label="Test Case",
|
494 |
+
placeholder="Enter your test case here...",
|
495 |
+
lines=2
|
496 |
+
)
|
497 |
+
|
498 |
+
# Result of execution
|
499 |
+
result_output = gr.Textbox(
|
500 |
+
label="Result of Execution",
|
501 |
+
placeholder="Execution result will be shown here...",
|
502 |
+
lines=2
|
503 |
+
)
|
504 |
+
|
505 |
+
with gr.Row():
|
506 |
+
sample_btn = gr.Button("Example Prompt")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
507 |
|
508 |
+
with gr.Row():
|
509 |
+
generate_btn = gr.Button("Generate", variant="primary")
|
510 |
+
clear_btn = gr.Button("Clear")
|
511 |
+
check_btn = gr.Button("Run test case")
|
512 |
|
513 |
# Generation Settings
|
514 |
with gr.Accordion("Generation Settings"):
|
|
|
624 |
|
625 |
sample_btn.click(
|
626 |
fn=get_example_input,
|
627 |
+
outputs=[prefix_input, output_vis, suffix_input, test_case_input, task_id_input, result_output],
|
628 |
queue=False
|
629 |
)
|
630 |
return demo
|
eval.py
DELETED
@@ -1,204 +0,0 @@
|
|
1 |
-
import ast
|
2 |
-
import contextlib
|
3 |
-
import faulthandler
|
4 |
-
import io
|
5 |
-
import multiprocessing
|
6 |
-
import os
|
7 |
-
import platform
|
8 |
-
import signal
|
9 |
-
import tempfile
|
10 |
-
from typing import Callable, Dict, Optional
|
11 |
-
|
12 |
-
|
13 |
-
import subprocess
|
14 |
-
import time
|
15 |
-
from multiprocessing import Process, Queue
|
16 |
-
|
17 |
-
import io
|
18 |
-
import sys
|
19 |
-
|
20 |
-
def unsafe_execute(problem, completion, timeout=3):
|
21 |
-
check_program = (
|
22 |
-
problem["prompt"]
|
23 |
-
+ completion
|
24 |
-
+ problem["suffix"]
|
25 |
-
+ "\n"
|
26 |
-
+ problem["test"]
|
27 |
-
+ "\n"
|
28 |
-
+ f"check({problem['entry_point']})"
|
29 |
-
)
|
30 |
-
|
31 |
-
old_stdout = sys.stdout
|
32 |
-
old_stderr = sys.stderr
|
33 |
-
new_stdout = io.StringIO()
|
34 |
-
new_stderr = io.StringIO()
|
35 |
-
sys.stdout = new_stdout
|
36 |
-
sys.stderr = new_stderr
|
37 |
-
|
38 |
-
try:
|
39 |
-
exec(check_program, {})
|
40 |
-
output = new_stdout.getvalue().strip()
|
41 |
-
error_output = new_stderr.getvalue().strip()
|
42 |
-
except Exception as e:
|
43 |
-
output = ''
|
44 |
-
error_output = traceback.format_exc()
|
45 |
-
finally:
|
46 |
-
sys.stdout = old_stdout
|
47 |
-
sys.stderr = old_stderr
|
48 |
-
|
49 |
-
if output and not error_output:
|
50 |
-
return output
|
51 |
-
elif not output and not error_output:
|
52 |
-
return 'Pass all test cases!'
|
53 |
-
else:
|
54 |
-
return f'Error: {error_output}'
|
55 |
-
|
56 |
-
|
57 |
-
@contextlib.contextmanager
|
58 |
-
def time_limit(seconds: float):
|
59 |
-
def signal_handler(signum, frame):
|
60 |
-
raise TimeoutException("Timed out!")
|
61 |
-
|
62 |
-
signal.setitimer(signal.ITIMER_REAL, seconds)
|
63 |
-
signal.signal(signal.SIGALRM, signal_handler)
|
64 |
-
try:
|
65 |
-
yield
|
66 |
-
finally:
|
67 |
-
signal.setitimer(signal.ITIMER_REAL, 0)
|
68 |
-
|
69 |
-
|
70 |
-
@contextlib.contextmanager
|
71 |
-
def swallow_io():
|
72 |
-
stream = WriteOnlyStringIO()
|
73 |
-
with contextlib.redirect_stdout(stream):
|
74 |
-
with contextlib.redirect_stderr(stream):
|
75 |
-
with redirect_stdin(stream):
|
76 |
-
yield
|
77 |
-
|
78 |
-
|
79 |
-
@contextlib.contextmanager
|
80 |
-
def create_tempdir():
|
81 |
-
with tempfile.TemporaryDirectory() as dirname:
|
82 |
-
with chdir(dirname):
|
83 |
-
yield dirname
|
84 |
-
|
85 |
-
|
86 |
-
class TimeoutException(Exception):
|
87 |
-
pass
|
88 |
-
|
89 |
-
|
90 |
-
class WriteOnlyStringIO(io.StringIO):
|
91 |
-
"""StringIO that throws an exception when it's read from"""
|
92 |
-
|
93 |
-
def read(self, *args, **kwargs):
|
94 |
-
raise IOError
|
95 |
-
|
96 |
-
def readline(self, *args, **kwargs):
|
97 |
-
raise IOError
|
98 |
-
|
99 |
-
def readlines(self, *args, **kwargs):
|
100 |
-
raise IOError
|
101 |
-
|
102 |
-
def readable(self, *args, **kwargs):
|
103 |
-
"""Returns True if the IO object can be read."""
|
104 |
-
return False
|
105 |
-
|
106 |
-
|
107 |
-
class redirect_stdin(contextlib._RedirectStream): # type: ignore
|
108 |
-
_stream = "stdin"
|
109 |
-
|
110 |
-
|
111 |
-
@contextlib.contextmanager
|
112 |
-
def chdir(root):
|
113 |
-
if root == ".":
|
114 |
-
yield
|
115 |
-
return
|
116 |
-
cwd = os.getcwd()
|
117 |
-
os.chdir(root)
|
118 |
-
try:
|
119 |
-
yield
|
120 |
-
except BaseException as exc:
|
121 |
-
raise exc
|
122 |
-
finally:
|
123 |
-
os.chdir(cwd)
|
124 |
-
|
125 |
-
|
126 |
-
def reliability_guard(maximum_memory_bytes: Optional[int] = None):
|
127 |
-
"""
|
128 |
-
This disables various destructive functions and prevents the generated code
|
129 |
-
from interfering with the test (e.g. fork bomb, killing other processes,
|
130 |
-
removing filesystem files, etc.)
|
131 |
-
|
132 |
-
WARNING
|
133 |
-
This function is NOT a security sandbox. Untrusted code, including, model-
|
134 |
-
generated code, should not be blindly executed outside of one. See the
|
135 |
-
Codex paper for more information about OpenAI's code sandbox, and proceed
|
136 |
-
with caution.
|
137 |
-
"""
|
138 |
-
|
139 |
-
if maximum_memory_bytes is not None:
|
140 |
-
import resource
|
141 |
-
|
142 |
-
resource.setrlimit(resource.RLIMIT_AS, (maximum_memory_bytes, maximum_memory_bytes))
|
143 |
-
resource.setrlimit(resource.RLIMIT_DATA, (maximum_memory_bytes, maximum_memory_bytes))
|
144 |
-
if not platform.uname().system == "Darwin":
|
145 |
-
resource.setrlimit(resource.RLIMIT_STACK, (maximum_memory_bytes, maximum_memory_bytes))
|
146 |
-
|
147 |
-
faulthandler.disable()
|
148 |
-
|
149 |
-
import builtins
|
150 |
-
|
151 |
-
builtins.exit = None
|
152 |
-
builtins.quit = None
|
153 |
-
|
154 |
-
import os
|
155 |
-
|
156 |
-
os.environ["OMP_NUM_THREADS"] = "1"
|
157 |
-
|
158 |
-
os.kill = None
|
159 |
-
os.system = None
|
160 |
-
os.putenv = None
|
161 |
-
os.remove = None
|
162 |
-
os.removedirs = None
|
163 |
-
os.rmdir = None
|
164 |
-
os.fchdir = None
|
165 |
-
os.setuid = None
|
166 |
-
os.fork = None
|
167 |
-
os.forkpty = None
|
168 |
-
os.killpg = None
|
169 |
-
os.rename = None
|
170 |
-
os.renames = None
|
171 |
-
os.truncate = None
|
172 |
-
os.replace = None
|
173 |
-
os.unlink = None
|
174 |
-
os.fchmod = None
|
175 |
-
os.fchown = None
|
176 |
-
os.chmod = None
|
177 |
-
os.chown = None
|
178 |
-
os.chroot = None
|
179 |
-
os.fchdir = None
|
180 |
-
os.lchflags = None
|
181 |
-
os.lchmod = None
|
182 |
-
os.lchown = None
|
183 |
-
os.getcwd = None
|
184 |
-
os.chdir = None
|
185 |
-
|
186 |
-
import shutil
|
187 |
-
|
188 |
-
shutil.rmtree = None
|
189 |
-
shutil.move = None
|
190 |
-
shutil.chown = None
|
191 |
-
|
192 |
-
import subprocess
|
193 |
-
|
194 |
-
subprocess.Popen = None # type: ignore
|
195 |
-
|
196 |
-
__builtins__["help"] = None
|
197 |
-
|
198 |
-
import sys
|
199 |
-
|
200 |
-
sys.modules["ipdb"] = None
|
201 |
-
sys.modules["joblib"] = None
|
202 |
-
sys.modules["resource"] = None
|
203 |
-
sys.modules["psutil"] = None
|
204 |
-
sys.modules["tkinter"] = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|