Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,10 @@ import os
|
|
5 |
import threading
|
6 |
import time
|
7 |
import uuid
|
|
|
|
|
|
|
|
|
8 |
|
9 |
class Logger:
|
10 |
def __init__(self, filename):
|
@@ -34,8 +38,10 @@ def generate_command(
|
|
34 |
command = [default_command]
|
35 |
|
36 |
if jsonl_file is not None:
|
37 |
-
|
38 |
-
|
|
|
|
|
39 |
|
40 |
command.extend(["--split", split, "--subset", subset])
|
41 |
|
@@ -61,6 +67,21 @@ def generate_command(
|
|
61 |
return " ".join(command)
|
62 |
|
63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
def run_bigcodebench(command):
|
65 |
global is_running
|
66 |
is_running = True
|
@@ -82,23 +103,27 @@ def run_bigcodebench(command):
|
|
82 |
is_running = False
|
83 |
yield "Evaluation completed.\n"
|
84 |
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
global is_running
|
|
|
|
|
87 |
if is_running:
|
88 |
yield "A command is already running. Please wait for it to finish.\n"
|
89 |
return
|
90 |
|
|
|
|
|
|
|
91 |
log_content = []
|
92 |
for log_line in run_bigcodebench(command):
|
93 |
log_content.append(log_line)
|
94 |
yield "".join(log_content)
|
95 |
-
|
96 |
-
|
97 |
-
def read_logs(log_file):
|
98 |
-
if os.path.exists(log_file):
|
99 |
-
with open(log_file, "r") as f:
|
100 |
-
return f.read()
|
101 |
-
return ""
|
102 |
|
103 |
|
104 |
with gr.Blocks() as demo:
|
@@ -113,20 +138,23 @@ with gr.Blocks() as demo:
|
|
113 |
save_pass_rate = gr.Checkbox(label="Save Pass Rate")
|
114 |
parallel = gr.Number(label="Parallel (optional)", precision=0)
|
115 |
min_time_limit = gr.Number(label="Min Time Limit", value=1, precision=1)
|
116 |
-
max_as_limit = gr.Number(label="Max AS Limit", value=
|
117 |
|
118 |
with gr.Row():
|
119 |
-
max_data_limit = gr.Number(label="Max Data Limit", value=
|
120 |
-
max_stack_limit = gr.Number(label="Max Stack Limit", value=
|
121 |
check_gt_only = gr.Checkbox(label="Check GT Only")
|
122 |
no_gt = gr.Checkbox(label="No GT")
|
123 |
|
124 |
command_output = gr.Textbox(label="Command", value=default_command, interactive=False)
|
125 |
-
|
126 |
-
|
|
|
|
|
127 |
|
128 |
-
# Hidden component to store the
|
129 |
-
|
|
|
130 |
def update_command(*args):
|
131 |
return generate_command(*args)
|
132 |
|
@@ -139,18 +167,25 @@ with gr.Blocks() as demo:
|
|
139 |
for component in input_components:
|
140 |
component.change(update_command, inputs=input_components, outputs=command_output)
|
141 |
|
142 |
-
def
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
|
155 |
# def update_logs(session_log_file):
|
156 |
# return read_logs(session_log_file)
|
|
|
5 |
import threading
|
6 |
import time
|
7 |
import uuid
|
8 |
+
import glob
|
9 |
+
import shutil
|
10 |
+
import urllib
|
11 |
+
from pathlib import Path
|
12 |
|
13 |
class Logger:
|
14 |
def __init__(self, filename):
|
|
|
38 |
command = [default_command]
|
39 |
|
40 |
if jsonl_file is not None:
|
41 |
+
# Copy the uploaded file to the current directory
|
42 |
+
local_filename = os.path.basename(jsonl_file.name)
|
43 |
+
shutil.copy(jsonl_file.name, local_filename)
|
44 |
+
command.extend(["--samples", local_filename])
|
45 |
|
46 |
command.extend(["--split", split, "--subset", subset])
|
47 |
|
|
|
67 |
return " ".join(command)
|
68 |
|
69 |
|
70 |
+
def cleanup_previous_files(jsonl_file=None):
|
71 |
+
for file in glob.glob("*.json") + glob.glob("*.log") + glob.glob("*.jsonl"):
|
72 |
+
try:
|
73 |
+
if jsonl_file is not None and file == jsonl_file:
|
74 |
+
continue
|
75 |
+
os.remove(file)
|
76 |
+
except Exception as e:
|
77 |
+
print(f"Error during cleanup of {file}: {e}")
|
78 |
+
|
79 |
+
def find_result_file():
|
80 |
+
json_files = glob.glob("*.json")
|
81 |
+
if json_files:
|
82 |
+
return max(json_files, key=os.path.getmtime)
|
83 |
+
return None
|
84 |
+
|
85 |
def run_bigcodebench(command):
|
86 |
global is_running
|
87 |
is_running = True
|
|
|
103 |
is_running = False
|
104 |
yield "Evaluation completed.\n"
|
105 |
|
106 |
+
result_file = find_result_file()
|
107 |
+
if result_file:
|
108 |
+
yield f"Result file found: {result_file}\n"
|
109 |
+
else:
|
110 |
+
yield "No result file found.\n"
|
111 |
+
|
112 |
+
def stream_logs(command, jsonl_file=None):
|
113 |
global is_running
|
114 |
+
if jsonl_file is not None:
|
115 |
+
local_filename = os.path.basename(jsonl_file.name)
|
116 |
if is_running:
|
117 |
yield "A command is already running. Please wait for it to finish.\n"
|
118 |
return
|
119 |
|
120 |
+
cleanup_previous_files(local_filename)
|
121 |
+
yield "Cleaned up previous files.\n"
|
122 |
+
|
123 |
log_content = []
|
124 |
for log_line in run_bigcodebench(command):
|
125 |
log_content.append(log_line)
|
126 |
yield "".join(log_content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
|
128 |
|
129 |
with gr.Blocks() as demo:
|
|
|
138 |
save_pass_rate = gr.Checkbox(label="Save Pass Rate")
|
139 |
parallel = gr.Number(label="Parallel (optional)", precision=0)
|
140 |
min_time_limit = gr.Number(label="Min Time Limit", value=1, precision=1)
|
141 |
+
max_as_limit = gr.Number(label="Max AS Limit", value=30*1024, precision=0)
|
142 |
|
143 |
with gr.Row():
|
144 |
+
max_data_limit = gr.Number(label="Max Data Limit", value=30*1024, precision=0)
|
145 |
+
max_stack_limit = gr.Number(label="Max Stack Limit", value=20, precision=0)
|
146 |
check_gt_only = gr.Checkbox(label="Check GT Only")
|
147 |
no_gt = gr.Checkbox(label="No GT")
|
148 |
|
149 |
command_output = gr.Textbox(label="Command", value=default_command, interactive=False)
|
150 |
+
with gr.Row():
|
151 |
+
submit_btn = gr.Button("Run Evaluation")
|
152 |
+
download_btn = gr.DownloadButton(label="Download Result", visible=False)
|
153 |
+
log_output = gr.Textbox(label="Execution Logs", lines=20)
|
154 |
|
155 |
+
# Hidden component to store the result file path
|
156 |
+
# result_file_path = gr.State("")
|
157 |
+
|
158 |
def update_command(*args):
|
159 |
return generate_command(*args)
|
160 |
|
|
|
167 |
for component in input_components:
|
168 |
component.change(update_command, inputs=input_components, outputs=command_output)
|
169 |
|
170 |
+
def start_evaluation(command, jsonl_file):
|
171 |
+
for log in stream_logs(command, jsonl_file):
|
172 |
+
yield log, gr.update(), gr.update()
|
173 |
+
|
174 |
+
result_file = find_result_file()
|
175 |
+
if result_file:
|
176 |
+
print(f"Result file: {result_file}")
|
177 |
+
urllib.request.urlretrieve(result_file, result_file)
|
178 |
+
return (gr.update(label="Evaluation completed. Result file found."),
|
179 |
+
gr.Button(visible=False),
|
180 |
+
gr.DownloadButton(label="Download Result", value=result_file))
|
181 |
+
else:
|
182 |
+
return (gr.update(label="Evaluation completed. No result file found."),
|
183 |
+
gr.Button("Run Evaluation"),
|
184 |
+
gr.DownloadButton(visible=False))
|
185 |
+
|
186 |
+
submit_btn.click(start_evaluation,
|
187 |
+
inputs=[command_output, jsonl_file],
|
188 |
+
outputs=[log_output, submit_btn, download_btn])
|
189 |
|
190 |
# def update_logs(session_log_file):
|
191 |
# return read_logs(session_log_file)
|