Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
|
|
|
|
3 |
import requests
|
4 |
import os
|
5 |
import shutil
|
@@ -7,41 +9,84 @@ import json
|
|
7 |
import pandas as pd
|
8 |
import subprocess
|
9 |
import plotly.express as px
|
10 |
-
def on_confirm(dataset_radio, num_parts_dropdown, token_counts_radio, line_counts_radio, cyclomatic_complexity_radio,
|
11 |
-
|
12 |
num_parts = num_parts_dropdown
|
13 |
-
token_counts_split = token_counts_radio
|
14 |
-
line_counts_split = line_counts_radio
|
15 |
-
cyclomatic_complexity_split = cyclomatic_complexity_radio
|
16 |
|
|
|
|
|
17 |
dataframes = []
|
18 |
-
if
|
19 |
-
token_counts_df = pd.read_csv(f"/
|
20 |
dataframes.append(token_counts_df)
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
24 |
dataframes.append(line_counts_df)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
if
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
33 |
if len(dataframes) > 0:
|
34 |
combined_df = dataframes[0]
|
35 |
for df in dataframes[1:]:
|
36 |
combined_df = pd.merge(combined_df, df, left_index=True, right_index=True, suffixes=('', '_y'))
|
37 |
-
combined_df = combined_df.loc[:, ~combined_df.columns.str.endswith('_y')]
|
38 |
return combined_df
|
39 |
else:
|
40 |
return pd.DataFrame()
|
41 |
|
42 |
|
43 |
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
def execute_specified_python_files(directory_list, file_list):
|
46 |
for directory in directory_list:
|
47 |
for py_file in file_list:
|
@@ -49,42 +94,92 @@ def execute_specified_python_files(directory_list, file_list):
|
|
49 |
if os.path.isfile(file_path) and py_file.endswith('.py'):
|
50 |
print(f"Executing {file_path}...")
|
51 |
try:
|
|
|
52 |
subprocess.run(['python', file_path], check=True)
|
53 |
print(f"{file_path} executed successfully.")
|
54 |
except subprocess.CalledProcessError as e:
|
55 |
print(f"Error executing {file_path}: {e}")
|
56 |
else:
|
57 |
print(f"File {file_path} does not exist or is not a Python file.")
|
58 |
-
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
|
62 |
def generate_file(file_obj, user_string, user_number,dataset_choice):
|
63 |
tmpdir = 'tmpdir'
|
64 |
|
65 |
-
|
66 |
FilePath = file_obj.name
|
|
|
67 |
|
|
|
68 |
shutil.copy(file_obj.name, tmpdir)
|
69 |
|
70 |
-
|
71 |
FileName = os.path.basename(file_obj.name)
|
72 |
|
73 |
print(FilePath)
|
74 |
-
|
|
|
|
|
75 |
with open(FilePath, 'r', encoding="utf-8") as file_obj:
|
76 |
-
|
77 |
outputPath = os.path.join('F:/Desktop/test', FileName)
|
78 |
data = json.load(file_obj)
|
79 |
print("data:", data)
|
80 |
|
81 |
-
|
82 |
with open(outputPath, 'w', encoding="utf-8") as w:
|
83 |
json.dump(data, w, ensure_ascii=False, indent=4)
|
84 |
|
85 |
-
|
86 |
-
file_content = json.dumps(data)
|
87 |
-
url = "http://localhost:6222/submit"
|
88 |
files = {'file': (FileName, file_content, 'application/json')}
|
89 |
payload = {
|
90 |
'user_string': user_string,
|
@@ -94,19 +189,21 @@ def generate_file(file_obj, user_string, user_number,dataset_choice):
|
|
94 |
|
95 |
response = requests.post(url, files=files, data=payload)
|
96 |
print(response)
|
97 |
-
|
98 |
if response.status_code == 200:
|
99 |
-
|
100 |
output_data = response.json()
|
101 |
|
102 |
-
|
103 |
-
output_file_path = os.path.join('E:/python-testn/pythonProject3/
|
104 |
with open(output_file_path, 'w', encoding="utf-8") as f:
|
105 |
json.dump(output_data, f, ensure_ascii=False, indent=4)
|
106 |
|
107 |
print(f"File saved at: {output_file_path}")
|
108 |
-
|
109 |
-
|
|
|
|
|
110 |
|
111 |
execute_specified_python_files(directory_list, file_list)
|
112 |
|
@@ -114,53 +211,70 @@ def generate_file(file_obj, user_string, user_number,dataset_choice):
|
|
114 |
else:
|
115 |
return {"status": "error", "message": response.text}
|
116 |
|
|
|
117 |
return {"status": "success", "message": response.text}
|
118 |
|
119 |
def update_radio_options(token_counts, line_counts, cyclomatic_complexity, problem_type):
|
120 |
options = []
|
121 |
if token_counts:
|
122 |
-
options.append("
|
123 |
if line_counts:
|
124 |
-
options.append("
|
125 |
if cyclomatic_complexity:
|
126 |
-
options.append("
|
127 |
if problem_type:
|
128 |
options.append("Problem Type")
|
129 |
|
130 |
return gr.update(choices=options)
|
131 |
|
132 |
def plot_csv(radio,num):
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
elif radio=="Token Counts in Prompt":
|
137 |
radio_choice="token_counts"
|
138 |
-
file_path = f'/
|
139 |
-
elif radio=="
|
|
|
|
|
|
|
140 |
radio_choice="CC"
|
141 |
-
file_path = f'/
|
142 |
elif radio=="Problem Type":
|
143 |
radio_choice="problem_type"
|
144 |
-
file_path = f'/
|
145 |
-
|
|
|
|
|
146 |
df = pd.read_csv(file_path)
|
147 |
-
|
148 |
df.set_index('Model', inplace=True)
|
149 |
|
|
|
150 |
df_transposed = df.T
|
151 |
|
|
|
152 |
fig = px.line(df_transposed, x=df_transposed.index, y=df_transposed.columns,
|
153 |
title='Model Evaluation Results',
|
154 |
labels={'value': 'Evaluation Score', 'index': 'Evaluation Metric'},
|
155 |
color_discrete_sequence=px.colors.qualitative.Plotly)
|
156 |
|
|
|
157 |
fig.update_traces(hovertemplate='%{y}')
|
158 |
|
159 |
return fig
|
160 |
|
|
|
|
|
|
|
|
|
|
|
161 |
with gr.Blocks() as iface:
|
162 |
gr.HTML("""
|
163 |
<style>
|
|
|
|
|
|
|
|
|
164 |
.title {
|
165 |
text-align: center;
|
166 |
font-size: 3em;
|
@@ -173,7 +287,7 @@ with gr.Blocks() as iface:
|
|
173 |
margin-bottom: 1em;
|
174 |
}
|
175 |
</style>
|
176 |
-
|
177 |
""")
|
178 |
|
179 |
with gr.Tabs() as tabs:
|
@@ -184,43 +298,48 @@ with gr.Blocks() as iface:
|
|
184 |
with gr.Column():
|
185 |
dataset_radio = gr.Radio(["HumanEval", "MBPP"], label="Select Dataset ")
|
186 |
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
with gr.Column():
|
200 |
-
gr.Markdown(
|
201 |
-
f"{custom_css}<div class='markdown-class'> Choose Classification Perspective </div>")
|
202 |
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
|
212 |
with gr.Row():
|
213 |
with gr.Column():
|
214 |
token_counts_radio = gr.Radio(
|
215 |
-
["Equal Frequency Partitioning", "Equal Interval Partitioning"], label="
|
216 |
visible=False)
|
217 |
with gr.Column():
|
218 |
line_counts_radio = gr.Radio(
|
219 |
-
["Equal Frequency Partitioning", "Equal Interval Partitioning"], label="
|
220 |
visible=False)
|
221 |
with gr.Column():
|
222 |
cyclomatic_complexity_radio = gr.Radio(
|
223 |
-
["Equal Frequency Partitioning", "Equal Interval Partitioning"], label="
|
224 |
visible=False)
|
225 |
|
226 |
token_counts_checkbox.change(fn=lambda x: toggle_radio(x, token_counts_radio),
|
@@ -232,16 +351,16 @@ with gr.Blocks() as iface:
|
|
232 |
outputs=cyclomatic_complexity_radio)
|
233 |
|
234 |
with gr.Tabs() as inner_tabs:
|
235 |
-
with gr.TabItem("
|
236 |
dataframe_output = gr.Dataframe(elem_id="dataframe")
|
237 |
css_output = gr.HTML()
|
238 |
confirm_button = gr.Button("Confirm ")
|
239 |
confirm_button.click(fn=on_confirm, inputs=[dataset_radio, num_parts_dropdown, token_counts_radio,
|
240 |
-
line_counts_radio, cyclomatic_complexity_radio],
|
241 |
outputs=dataframe_output)
|
242 |
|
243 |
with gr.TabItem("Line chart"):
|
244 |
-
select_radio = gr.Radio(choices=[])
|
245 |
checkboxes = [token_counts_checkbox, line_counts_checkbox, cyclomatic_complexity_checkbox,
|
246 |
problem_type_checkbox]
|
247 |
for checkbox in checkboxes:
|
@@ -249,13 +368,13 @@ with gr.Blocks() as iface:
|
|
249 |
select_radio.change(fn=plot_csv, inputs=[select_radio, num_parts_dropdown],
|
250 |
outputs=gr.Plot(label="Line Plot "))
|
251 |
|
252 |
-
with gr.TabItem("Upload"):
|
253 |
gr.Markdown("Upload a JSON file")
|
254 |
with gr.Row():
|
255 |
with gr.Column():
|
256 |
string_input = gr.Textbox(label="Enter the Model Name")
|
257 |
number_input = gr.Number(label="Select the Number of Samples")
|
258 |
-
dataset_choice = gr.Dropdown(label="Select Dataset", choices=["
|
259 |
with gr.Column():
|
260 |
file_input = gr.File(label="Upload Generation Result in JSON file")
|
261 |
upload_button = gr.Button("Confirm and Upload")
|
@@ -266,26 +385,30 @@ with gr.Blocks() as iface:
|
|
266 |
outputs=json_output)
|
267 |
|
268 |
|
269 |
-
|
270 |
def toggle_radio(checkbox, radio):
|
271 |
return gr.update(visible=checkbox)
|
272 |
|
273 |
|
274 |
-
|
275 |
css = """
|
276 |
#scale1 {
|
277 |
border: 1px solid rgba(0, 0, 0, 0.2);
|
278 |
padding: 10px;
|
279 |
-
border-radius: 8px;
|
280 |
-
background-color: #f9f9f9;
|
281 |
-
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
282 |
}
|
283 |
}
|
284 |
"""
|
285 |
gr.HTML(f"<style>{css}</style>")
|
286 |
|
287 |
|
|
|
|
|
|
|
|
|
|
|
288 |
|
289 |
|
290 |
-
|
291 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
+
from slider import create_subset_ratios_tab
|
4 |
+
from change_output import change_file
|
5 |
import requests
|
6 |
import os
|
7 |
import shutil
|
|
|
9 |
import pandas as pd
|
10 |
import subprocess
|
11 |
import plotly.express as px
|
12 |
+
def on_confirm(dataset_radio, num_parts_dropdown, token_counts_radio, line_counts_radio, cyclomatic_complexity_radio, problem_type_checkbox):
|
13 |
+
# 根据用户选择的参数构建文件路径
|
14 |
num_parts = num_parts_dropdown
|
15 |
+
# token_counts_split = token_counts_radio
|
16 |
+
# line_counts_split = line_counts_radio
|
17 |
+
# cyclomatic_complexity_split = cyclomatic_complexity_radio
|
18 |
|
19 |
+
|
20 |
+
# 读取数据
|
21 |
dataframes = []
|
22 |
+
if token_counts_radio=="Equal Frequency Partitioning":#等频划分,每个子集数据点的数量基本一致
|
23 |
+
token_counts_df = pd.read_csv(f"E:/python-testn/pythonProject3/hh_2/dividing_into_different_subsets/{num_parts}/QS/token_counts_QS.csv")
|
24 |
dataframes.append(token_counts_df)
|
25 |
+
if token_counts_radio=="Equal Interval Partitioning":
|
26 |
+
token_counts_df = pd.read_csv(f"E:/python-testn/pythonProject3/hh_2/dividing_into_different_subsets/{num_parts}/EI/token_counts_EI.csv")
|
27 |
+
dataframes.append(token_counts_df)
|
28 |
+
if line_counts_radio=="Equal Frequency Partitioning":#等频划分,每个子集数据点的数量基本一致
|
29 |
+
line_counts_df = pd.read_csv(f"E:/python-testn/pythonProject3/hh_2/dividing_into_different_subsets/{num_parts}/QS/line_counts_QS.csv")
|
30 |
dataframes.append(line_counts_df)
|
31 |
+
if token_counts_radio=="Equal Interval Partitioning":
|
32 |
+
line_counts_df = pd.read_csv(f"E:/python-testn/pythonProject3/hh_2/dividing_into_different_subsets/{num_parts}/EI/line_counts_EI.csv")
|
33 |
+
dataframes.append(line_counts_df)
|
34 |
+
if cyclomatic_complexity_radio=="Equal Frequency Partitioning":#等频划分,每个子集数据点的数量基本一致
|
35 |
+
CC_df = pd.read_csv(f"E:/python-testn/pythonProject3/hh_2/dividing_into_different_subsets/{num_parts}/QS/CC_QS.csv")
|
36 |
+
dataframes.append(CC_df)
|
37 |
+
if token_counts_radio=="Equal Interval Partitioning":
|
38 |
+
CC_df = pd.read_csv(f"E:/python-testn/pythonProject3/hh_2/dividing_into_different_subsets/{num_parts}/EI/CC_EI.csv")
|
39 |
+
dataframes.append(CC_df)
|
40 |
|
41 |
+
|
42 |
+
|
43 |
+
#以下改为直接从一个划分文件中读取即可
|
44 |
+
if problem_type_checkbox:
|
45 |
+
problem_type_df = pd.read_csv("E:/python-testn/pythonProject3/hh_2/dividing_into_different_subsets/cata_result.csv")
|
46 |
+
dataframes.append(problem_type_df)
|
47 |
+
|
48 |
+
# 如果所有三个radio都有value,将三个文件中的所有行拼接
|
49 |
if len(dataframes) > 0:
|
50 |
combined_df = dataframes[0]
|
51 |
for df in dataframes[1:]:
|
52 |
combined_df = pd.merge(combined_df, df, left_index=True, right_index=True, suffixes=('', '_y'))
|
53 |
+
combined_df = combined_df.loc[:, ~combined_df.columns.str.endswith('_y')] # 去除重复的列
|
54 |
return combined_df
|
55 |
else:
|
56 |
return pd.DataFrame()
|
57 |
|
58 |
|
59 |
|
60 |
+
# 定义一个函数来返回数据
|
61 |
+
# def show_data(line_counts, token_counts, cyclomatic_complexity, problem_type, show_high, show_medium, show_low):
|
62 |
+
# columns = ["Model"]
|
63 |
+
#
|
64 |
+
# if token_counts:
|
65 |
+
# if show_high:
|
66 |
+
# columns.append("Token Counts.I")
|
67 |
+
#
|
68 |
+
# if show_medium:
|
69 |
+
# columns.append("Token Counts.II")
|
70 |
+
# if show_low:
|
71 |
+
# columns.append("Token Counts.III")
|
72 |
+
# if line_counts:
|
73 |
+
# if show_high:
|
74 |
+
# columns.append("Line Counts.I")
|
75 |
+
# if show_medium:
|
76 |
+
# columns.append("Line Counts.II")
|
77 |
+
# if show_low:
|
78 |
+
# columns.append("Line Counts.III")
|
79 |
+
# if cyclomatic_complexity:
|
80 |
+
# if show_high:
|
81 |
+
# columns.append("Cyclomatic Complexity.I")
|
82 |
+
# if show_medium:
|
83 |
+
# columns.append("Cyclomatic Complexity.II")
|
84 |
+
# if show_low:
|
85 |
+
# columns.append("Cyclomatic Complexity.III")
|
86 |
+
# if problem_type:
|
87 |
+
# columns.extend(["Problem Type_String", "Problem Type_Math", "Problem Type_Array"])
|
88 |
+
# return data[columns]
|
89 |
+
#用于更新数据文件的部分
|
90 |
def execute_specified_python_files(directory_list, file_list):
|
91 |
for directory in directory_list:
|
92 |
for py_file in file_list:
|
|
|
94 |
if os.path.isfile(file_path) and py_file.endswith('.py'):
|
95 |
print(f"Executing {file_path}...")
|
96 |
try:
|
97 |
+
# 使用subprocess执行Python文件
|
98 |
subprocess.run(['python', file_path], check=True)
|
99 |
print(f"{file_path} executed successfully.")
|
100 |
except subprocess.CalledProcessError as e:
|
101 |
print(f"Error executing {file_path}: {e}")
|
102 |
else:
|
103 |
print(f"File {file_path} does not exist or is not a Python file.")
|
104 |
+
# 定义一个函数来生成 CSS 样式
|
105 |
+
def generate_css(line_counts, token_counts, cyclomatic_complexity, problem_type, show_high, show_medium, show_low):
|
106 |
+
css = """
|
107 |
+
#dataframe th {
|
108 |
+
background-color: #f2f2f2
|
109 |
+
|
110 |
+
}
|
111 |
+
"""
|
112 |
+
colors = ["#e6f7ff", "#ffeecc", "#e6ffe6", "#ffe6e6"]
|
113 |
+
categories = [line_counts, token_counts, cyclomatic_complexity]
|
114 |
+
category_index = 0
|
115 |
+
column_index = 1
|
116 |
+
|
117 |
+
for category in categories:
|
118 |
+
if category:
|
119 |
+
if show_high:
|
120 |
+
css += f"#dataframe td:nth-child({column_index + 1}) {{ background-color: {colors[category_index]}; }}\n"
|
121 |
+
column_index += 1
|
122 |
+
if show_medium:
|
123 |
+
css += f"#dataframe td:nth-child({column_index + 1}) {{ background-color: {colors[category_index]}; }}\n"
|
124 |
+
column_index += 1
|
125 |
+
if show_low:
|
126 |
+
css += f"#dataframe td:nth-child({column_index + 1}) {{ background-color: {colors[category_index]}; }}\n"
|
127 |
+
column_index += 1
|
128 |
+
category_index += 1
|
129 |
+
|
130 |
+
# 为 Problem Type 相关的三个子列设置固定颜色
|
131 |
+
if problem_type:
|
132 |
+
problem_type_color = "#d4f0fc" # 你可以选择任何你喜欢的颜色
|
133 |
+
css += f"#dataframe td:nth-child({column_index + 1}) {{ background-color: {problem_type_color}; }}\n"
|
134 |
+
css += f"#dataframe td:nth-child({column_index + 2}) {{ background-color: {problem_type_color}; }}\n"
|
135 |
+
css += f"#dataframe td:nth-child({column_index + 3}) {{ background-color: {problem_type_color}; }}\n"
|
136 |
+
|
137 |
+
# 隐藏 "data" 标识
|
138 |
+
css += """
|
139 |
+
.gradio-container .dataframe-container::before {
|
140 |
+
content: none !important;
|
141 |
+
}
|
142 |
+
"""
|
143 |
+
|
144 |
+
return css
|
145 |
+
# def update_dataframe(line_counts, token_counts, cyclomatic_complexity, problem_type, show_high, show_medium,
|
146 |
+
# show_low):
|
147 |
+
# df = show_data(line_counts, token_counts, cyclomatic_complexity, problem_type, show_high, show_medium, show_low)
|
148 |
+
# css = generate_css(line_counts, token_counts, cyclomatic_complexity, problem_type, show_high, show_medium,
|
149 |
+
# show_low)
|
150 |
+
# return gr.update(value=df), gr.update(value=f"<style>{css}</style>")
|
151 |
|
152 |
|
153 |
def generate_file(file_obj, user_string, user_number,dataset_choice):
|
154 |
tmpdir = 'tmpdir'
|
155 |
|
156 |
+
print('临时文件夹地址:{}'.format(tmpdir))
|
157 |
FilePath = file_obj.name
|
158 |
+
print('上传文件的地址:{}'.format(file_obj.name)) # 输出上传后的文件在gradio中保存的绝对地址
|
159 |
|
160 |
+
# 将文件复制到临时目录中
|
161 |
shutil.copy(file_obj.name, tmpdir)
|
162 |
|
163 |
+
# 获取上传Gradio的文件名称
|
164 |
FileName = os.path.basename(file_obj.name)
|
165 |
|
166 |
print(FilePath)
|
167 |
+
# 获取拷贝在临时目录的新的文件地址
|
168 |
+
|
169 |
+
# 打开复制到新路径后的文件
|
170 |
with open(FilePath, 'r', encoding="utf-8") as file_obj:
|
171 |
+
# 在本地电脑打开一个新的文件,并且将上传文件内容写入到新文件
|
172 |
outputPath = os.path.join('F:/Desktop/test', FileName)
|
173 |
data = json.load(file_obj)
|
174 |
print("data:", data)
|
175 |
|
176 |
+
# 将数据写入新的 JSON 文件
|
177 |
with open(outputPath, 'w', encoding="utf-8") as w:
|
178 |
json.dump(data, w, ensure_ascii=False, indent=4)
|
179 |
|
180 |
+
# 读取文件内容并上传到服务器
|
181 |
+
file_content = json.dumps(data) # 将数据转换为 JSON 字符串
|
182 |
+
url = "http://localhost:6222/submit" # 替换为你的后端服务器地址
|
183 |
files = {'file': (FileName, file_content, 'application/json')}
|
184 |
payload = {
|
185 |
'user_string': user_string,
|
|
|
189 |
|
190 |
response = requests.post(url, files=files, data=payload)
|
191 |
print(response)
|
192 |
+
#返回服务器处理后的文件
|
193 |
if response.status_code == 200:
|
194 |
+
# 获取服务器返回的 JSON 数据
|
195 |
output_data = response.json()
|
196 |
|
197 |
+
# 保存 JSON 数据到本地
|
198 |
+
output_file_path = os.path.join('E:/python-testn/pythonProject3/hh_2/evaluate_result', 'new-model.json')
|
199 |
with open(output_file_path, 'w', encoding="utf-8") as f:
|
200 |
json.dump(output_data, f, ensure_ascii=False, indent=4)
|
201 |
|
202 |
print(f"File saved at: {output_file_path}")
|
203 |
+
|
204 |
+
# 调用更新数据文件的函数
|
205 |
+
directory_list = ['E:\python-testn\pythonProject3\hh_2\dividing_into_different_subsets\5\QS'] # 替换为你的目录路径列表
|
206 |
+
file_list = ["calculate_humaneval_result.py"] # 替换为你想要执行的Python文件列表
|
207 |
|
208 |
execute_specified_python_files(directory_list, file_list)
|
209 |
|
|
|
211 |
else:
|
212 |
return {"status": "error", "message": response.text}
|
213 |
|
214 |
+
# 返回服务器响应
|
215 |
return {"status": "success", "message": response.text}
|
216 |
|
217 |
def update_radio_options(token_counts, line_counts, cyclomatic_complexity, problem_type):
|
218 |
options = []
|
219 |
if token_counts:
|
220 |
+
options.append("The Number of Tokens in Problem Descriptions")
|
221 |
if line_counts:
|
222 |
+
options.append("The Number of Lines in Problem Descriptions")
|
223 |
if cyclomatic_complexity:
|
224 |
+
options.append("The Complexity of Reference Code")
|
225 |
if problem_type:
|
226 |
options.append("Problem Type")
|
227 |
|
228 |
return gr.update(choices=options)
|
229 |
|
230 |
def plot_csv(radio,num):
|
231 |
+
# 读取本地的CSV文件
|
232 |
+
#token_counts_df = pd.read_csv(f"{num_parts}/QS/token_counts_QS.csv")
|
233 |
+
if radio=="The Number of Tokens in Problem Descriptions":
|
|
|
234 |
radio_choice="token_counts"
|
235 |
+
file_path = f'E:/python-testn/pythonProject3/hh_2/dividing_into_different_subsets/{num}/QS/{radio_choice}_QS.csv'
|
236 |
+
elif radio=="The Number of Lines in Problem Descriptions":
|
237 |
+
radio_choice="line_counts"
|
238 |
+
file_path = f'E:/python-testn/pythonProject3/hh_2/dividing_into_different_subsets/{num}/QS/{radio_choice}_QS.csv'
|
239 |
+
elif radio=="The Complexity of Reference Code":
|
240 |
radio_choice="CC"
|
241 |
+
file_path = f'E:/python-testn/pythonProject3/hh_2/dividing_into_different_subsets/{num}/QS/{radio_choice}_QS.csv'
|
242 |
elif radio=="Problem Type":
|
243 |
radio_choice="problem_type"
|
244 |
+
file_path = f'E:/python-testn/pythonProject3/hh_2/dividing_into_different_subsets/cata_result.csv'
|
245 |
+
print("test!")
|
246 |
+
|
247 |
+
# file_path="E:/python-testn/pythonProject3/hh_1/dividing_into_different_subsets/3/QS/CC_QS.csv"
|
248 |
df = pd.read_csv(file_path)
|
249 |
+
# 将第一列作为索引
|
250 |
df.set_index('Model', inplace=True)
|
251 |
|
252 |
+
# 转置数据框,使得模型作为列,横轴作为行
|
253 |
df_transposed = df.T
|
254 |
|
255 |
+
# 使用plotly绘制折线图
|
256 |
fig = px.line(df_transposed, x=df_transposed.index, y=df_transposed.columns,
|
257 |
title='Model Evaluation Results',
|
258 |
labels={'value': 'Evaluation Score', 'index': 'Evaluation Metric'},
|
259 |
color_discrete_sequence=px.colors.qualitative.Plotly)
|
260 |
|
261 |
+
# 设置悬停效果
|
262 |
fig.update_traces(hovertemplate='%{y}')
|
263 |
|
264 |
return fig
|
265 |
|
266 |
+
|
267 |
+
|
268 |
+
# 创建 Gradio 界面
|
269 |
+
import gradio as gr
|
270 |
+
|
271 |
with gr.Blocks() as iface:
|
272 |
gr.HTML("""
|
273 |
<style>
|
274 |
+
# body {
|
275 |
+
# max-width: 50%; /* 设置最大宽度为50% */
|
276 |
+
# margin: 0 auto; /* 将内容居中 */
|
277 |
+
# }
|
278 |
.title {
|
279 |
text-align: center;
|
280 |
font-size: 3em;
|
|
|
287 |
margin-bottom: 1em;
|
288 |
}
|
289 |
</style>
|
290 |
+
|
291 |
""")
|
292 |
|
293 |
with gr.Tabs() as tabs:
|
|
|
298 |
with gr.Column():
|
299 |
dataset_radio = gr.Radio(["HumanEval", "MBPP"], label="Select Dataset ")
|
300 |
|
301 |
+
with gr.Row():
|
302 |
+
custom_css = """
|
303 |
+
<style>
|
304 |
+
.markdown-class {
|
305 |
+
font-family: 'Helvetica', sans-serif;
|
306 |
+
font-size: 20px;
|
307 |
+
font-weight: bold;
|
308 |
+
color: #333;
|
309 |
+
}
|
310 |
+
</style>
|
311 |
+
"""
|
|
|
|
|
|
|
|
|
312 |
|
313 |
+
with gr.Column():
|
314 |
+
gr.Markdown(
|
315 |
+
f"{custom_css}<div class='markdown-class'> Choose Division Perspective </div>")
|
316 |
+
|
317 |
+
token_counts_checkbox = gr.Checkbox(label="I-The Number of Tokens in Problem Descriptions")
|
318 |
+
line_counts_checkbox = gr.Checkbox(label="II-The Number of Lines in Problem Descriptions")
|
319 |
+
cyclomatic_complexity_checkbox = gr.Checkbox(label="III-The Complexity of Reference Code")
|
320 |
+
problem_type_checkbox = gr.Checkbox(label="IV-Problem Types ")
|
321 |
+
css_code = """
|
322 |
+
.dropdown-container {
|
323 |
+
display: none;
|
324 |
+
}
|
325 |
+
"""
|
326 |
|
327 |
+
with gr.Column():
|
328 |
+
# gr.Markdown("<div class='markdown-class'>Choose Subsets </div>")
|
329 |
+
num_parts_dropdown = gr.Dropdown(choices=[3, 4, 5, 6, 7, 8], label="Choose the Number of Subsets")
|
330 |
|
331 |
with gr.Row():
|
332 |
with gr.Column():
|
333 |
token_counts_radio = gr.Radio(
|
334 |
+
["Equal Frequency Partitioning", "Equal Interval Partitioning"], label="Choose the Division Method for Perspective-I",
|
335 |
visible=False)
|
336 |
with gr.Column():
|
337 |
line_counts_radio = gr.Radio(
|
338 |
+
["Equal Frequency Partitioning", "Equal Interval Partitioning"], label="Choose the Division Method for Perspective-II",
|
339 |
visible=False)
|
340 |
with gr.Column():
|
341 |
cyclomatic_complexity_radio = gr.Radio(
|
342 |
+
["Equal Frequency Partitioning", "Equal Interval Partitioning"], label="Choose the Division Method for Perspective-III",
|
343 |
visible=False)
|
344 |
|
345 |
token_counts_checkbox.change(fn=lambda x: toggle_radio(x, token_counts_radio),
|
|
|
351 |
outputs=cyclomatic_complexity_radio)
|
352 |
|
353 |
with gr.Tabs() as inner_tabs:
|
354 |
+
with gr.TabItem("Ranking Table"):
|
355 |
dataframe_output = gr.Dataframe(elem_id="dataframe")
|
356 |
css_output = gr.HTML()
|
357 |
confirm_button = gr.Button("Confirm ")
|
358 |
confirm_button.click(fn=on_confirm, inputs=[dataset_radio, num_parts_dropdown, token_counts_radio,
|
359 |
+
line_counts_radio, cyclomatic_complexity_radio,problem_type_checkbox],
|
360 |
outputs=dataframe_output)
|
361 |
|
362 |
with gr.TabItem("Line chart"):
|
363 |
+
select_radio = gr.Radio(choices=[],label="Select One Perpective")
|
364 |
checkboxes = [token_counts_checkbox, line_counts_checkbox, cyclomatic_complexity_checkbox,
|
365 |
problem_type_checkbox]
|
366 |
for checkbox in checkboxes:
|
|
|
368 |
select_radio.change(fn=plot_csv, inputs=[select_radio, num_parts_dropdown],
|
369 |
outputs=gr.Plot(label="Line Plot "))
|
370 |
|
371 |
+
with gr.TabItem("Upload Inference File"):
|
372 |
gr.Markdown("Upload a JSON file")
|
373 |
with gr.Row():
|
374 |
with gr.Column():
|
375 |
string_input = gr.Textbox(label="Enter the Model Name")
|
376 |
number_input = gr.Number(label="Select the Number of Samples")
|
377 |
+
dataset_choice = gr.Dropdown(label="Select Dataset", choices=["HumanEval", "MBPP"])
|
378 |
with gr.Column():
|
379 |
file_input = gr.File(label="Upload Generation Result in JSON file")
|
380 |
upload_button = gr.Button("Confirm and Upload")
|
|
|
385 |
outputs=json_output)
|
386 |
|
387 |
|
388 |
+
# 定义事件处理函数
|
389 |
def toggle_radio(checkbox, radio):
|
390 |
return gr.update(visible=checkbox)
|
391 |
|
392 |
|
|
|
393 |
css = """
|
394 |
#scale1 {
|
395 |
border: 1px solid rgba(0, 0, 0, 0.2);
|
396 |
padding: 10px;
|
397 |
+
border-radius: 8px;
|
398 |
+
background-color: #f9f9f9;
|
399 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
400 |
}
|
401 |
}
|
402 |
"""
|
403 |
gr.HTML(f"<style>{css}</style>")
|
404 |
|
405 |
|
406 |
+
# 初始化数据表格
|
407 |
+
# initial_df = show_data(False, False, False, False, False, False, False)
|
408 |
+
# initial_css = generate_css(False, False, False, False, True, False, False)
|
409 |
+
# dataframe_output.value = initial_df
|
410 |
+
# css_output.value = f"<style>{initial_css}</style>"
|
411 |
|
412 |
|
413 |
+
# 启动界面
|
414 |
iface.launch()
|