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