Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -18,19 +18,19 @@ def on_confirm(dataset_radio, num_parts_dropdown, token_counts_radio, line_count
|
|
18 |
token_counts_df = pd.read_csv(f"/home/user/app/dividing_into_different_subsets/{num_parts}/QS/token_counts_QS.csv")
|
19 |
dataframes.append(token_counts_df)
|
20 |
if token_counts_radio=="Equal Interval Partitioning":
|
21 |
-
token_counts_df = pd.read_csv(f"
|
22 |
dataframes.append(token_counts_df)
|
23 |
if line_counts_radio=="Equal Frequency Partitioning":#等频划分,每个子集数据点的数量基本一致
|
24 |
-
line_counts_df = pd.read_csv(f"
|
25 |
dataframes.append(line_counts_df)
|
26 |
if token_counts_radio=="Equal Interval Partitioning":
|
27 |
-
line_counts_df = pd.read_csv(f"
|
28 |
dataframes.append(line_counts_df)
|
29 |
if cyclomatic_complexity_radio=="Equal Frequency Partitioning":#等频划分,每个子集数据点的数量基本一致
|
30 |
-
CC_df = pd.read_csv(f"
|
31 |
dataframes.append(CC_df)
|
32 |
if token_counts_radio=="Equal Interval Partitioning":
|
33 |
-
CC_df = pd.read_csv(f"
|
34 |
dataframes.append(CC_df)
|
35 |
|
36 |
|
@@ -119,31 +119,30 @@ def generate_file(file_obj, user_string, user_number,dataset_choice):
|
|
119 |
|
120 |
print('临时文件夹地址:{}'.format(tmpdir))
|
121 |
FilePath = file_obj.name
|
122 |
-
print('上传文件的地址:{}'.format(file_obj.name))
|
|
|
123 |
|
124 |
-
# 将文件复制到临时目录中
|
125 |
shutil.copy(file_obj.name, tmpdir)
|
126 |
|
127 |
-
|
128 |
FileName = os.path.basename(file_obj.name)
|
129 |
|
130 |
print(FilePath)
|
131 |
-
|
|
|
132 |
|
133 |
-
# 打开复制到新路径后的文件
|
134 |
with open(FilePath, 'r', encoding="utf-8") as file_obj:
|
135 |
-
# 在本地电脑打开一个新的文件,并且将上传文件内容写入到新文件
|
136 |
outputPath = os.path.join('F:/Desktop/test', FileName)
|
137 |
data = json.load(file_obj)
|
138 |
print("data:", data)
|
139 |
|
140 |
-
|
141 |
with open(outputPath, 'w', encoding="utf-8") as w:
|
142 |
json.dump(data, w, ensure_ascii=False, indent=4)
|
143 |
|
144 |
-
|
145 |
-
file_content = json.dumps(data)
|
146 |
-
url = "http://localhost:6222/submit"
|
147 |
files = {'file': (FileName, file_content, 'application/json')}
|
148 |
payload = {
|
149 |
'user_string': user_string,
|
@@ -153,21 +152,21 @@ def generate_file(file_obj, user_string, user_number,dataset_choice):
|
|
153 |
|
154 |
response = requests.post(url, files=files, data=payload)
|
155 |
print(response)
|
156 |
-
|
157 |
if response.status_code == 200:
|
158 |
-
|
159 |
output_data = response.json()
|
160 |
|
161 |
-
|
162 |
-
output_file_path = os.path.join('
|
163 |
with open(output_file_path, 'w', encoding="utf-8") as f:
|
164 |
json.dump(output_data, f, ensure_ascii=False, indent=4)
|
165 |
|
166 |
print(f"File saved at: {output_file_path}")
|
167 |
|
168 |
-
|
169 |
-
directory_list = ['
|
170 |
-
file_list = ["calculate_humaneval_result.py"]
|
171 |
|
172 |
execute_specified_python_files(directory_list, file_list)
|
173 |
|
@@ -175,7 +174,7 @@ def generate_file(file_obj, user_string, user_number,dataset_choice):
|
|
175 |
else:
|
176 |
return {"status": "error", "message": response.text}
|
177 |
|
178 |
-
|
179 |
return {"status": "success", "message": response.text}
|
180 |
|
181 |
def update_radio_options(token_counts, line_counts, cyclomatic_complexity, problem_type):
|
@@ -192,44 +191,32 @@ def update_radio_options(token_counts, line_counts, cyclomatic_complexity, probl
|
|
192 |
return gr.update(choices=options)
|
193 |
|
194 |
def plot_csv(radio,num):
|
195 |
-
|
196 |
-
#token_counts_df = pd.read_csv(f"{num_parts}/QS/token_counts_QS.csv")
|
197 |
if radio=="The Number of Tokens in Problem Descriptions":
|
198 |
radio_choice="token_counts"
|
199 |
-
file_path = f'
|
200 |
elif radio=="The Number of Lines in Problem Descriptions":
|
201 |
radio_choice="line_counts"
|
202 |
-
file_path = f'
|
203 |
elif radio=="The Complexity of Reference Code":
|
204 |
radio_choice="CC"
|
205 |
-
file_path = f'
|
206 |
elif radio=="Problem Type":
|
207 |
radio_choice="problem_type"
|
208 |
-
file_path = f'
|
209 |
-
print("test!")
|
210 |
-
|
211 |
-
# file_path="E:/python-testn/pythonProject3/hh_1/dividing_into_different_subsets/3/QS/CC_QS.csv"
|
212 |
df = pd.read_csv(file_path)
|
213 |
-
# 将第一列作为索引
|
214 |
df.set_index('Model', inplace=True)
|
215 |
|
216 |
-
# 转置数据框,使得模型作为列,横轴作为行
|
217 |
df_transposed = df.T
|
218 |
-
|
219 |
-
# 使用plotly绘制折线图
|
220 |
fig = px.line(df_transposed, x=df_transposed.index, y=df_transposed.columns,
|
221 |
title='Model Evaluation Results',
|
222 |
labels={'value': 'Evaluation Score', 'index': 'Evaluation Metric'},
|
223 |
color_discrete_sequence=px.colors.qualitative.Plotly)
|
224 |
-
|
225 |
-
# 设置悬停效果
|
226 |
fig.update_traces(hovertemplate='%{y}')
|
227 |
|
228 |
return fig
|
229 |
|
230 |
|
231 |
-
|
232 |
-
# 创建 Gradio 界面
|
233 |
import gradio as gr
|
234 |
|
235 |
with gr.Blocks() as iface:
|
@@ -349,7 +336,7 @@ with gr.Blocks() as iface:
|
|
349 |
outputs=json_output)
|
350 |
|
351 |
|
352 |
-
|
353 |
def toggle_radio(checkbox, radio):
|
354 |
return gr.update(visible=checkbox)
|
355 |
|
@@ -367,12 +354,4 @@ with gr.Blocks() as iface:
|
|
367 |
gr.HTML(f"<style>{css}</style>")
|
368 |
|
369 |
|
370 |
-
# 初始化数据表格
|
371 |
-
# initial_df = show_data(False, False, False, False, False, False, False)
|
372 |
-
# initial_css = generate_css(False, False, False, False, True, False, False)
|
373 |
-
# dataframe_output.value = initial_df
|
374 |
-
# css_output.value = f"<style>{initial_css}</style>"
|
375 |
-
|
376 |
-
|
377 |
-
# 启动界面
|
378 |
iface.launch()
|
|
|
18 |
token_counts_df = pd.read_csv(f"/home/user/app/dividing_into_different_subsets/{num_parts}/QS/token_counts_QS.csv")
|
19 |
dataframes.append(token_counts_df)
|
20 |
if token_counts_radio=="Equal Interval Partitioning":
|
21 |
+
token_counts_df = pd.read_csv(f"/home/user/app/dividing_into_different_subsets/{num_parts}/EI/token_counts_EI.csv")
|
22 |
dataframes.append(token_counts_df)
|
23 |
if line_counts_radio=="Equal Frequency Partitioning":#等频划分,每个子集数据点的数量基本一致
|
24 |
+
line_counts_df = pd.read_csv(f"/home/user/app/dividing_into_different_subsets/{num_parts}/QS/line_counts_QS.csv")
|
25 |
dataframes.append(line_counts_df)
|
26 |
if token_counts_radio=="Equal Interval Partitioning":
|
27 |
+
line_counts_df = pd.read_csv(f"/home/user/app/dividing_into_different_subsets/{num_parts}/EI/line_counts_EI.csv")
|
28 |
dataframes.append(line_counts_df)
|
29 |
if cyclomatic_complexity_radio=="Equal Frequency Partitioning":#等频划分,每个子集数据点的数量基本一致
|
30 |
+
CC_df = pd.read_csv(f"/home/user/app/dividing_into_different_subsets/{num_parts}/QS/CC_QS.csv")
|
31 |
dataframes.append(CC_df)
|
32 |
if token_counts_radio=="Equal Interval Partitioning":
|
33 |
+
CC_df = pd.read_csv(f"/home/user/app/dividing_into_different_subsets/{num_parts}/EI/CC_EI.csv")
|
34 |
dataframes.append(CC_df)
|
35 |
|
36 |
|
|
|
119 |
|
120 |
print('临时文件夹地址:{}'.format(tmpdir))
|
121 |
FilePath = file_obj.name
|
122 |
+
print('上传文件的地址:{}'.format(file_obj.name))
|
123 |
+
|
124 |
|
|
|
125 |
shutil.copy(file_obj.name, tmpdir)
|
126 |
|
127 |
+
|
128 |
FileName = os.path.basename(file_obj.name)
|
129 |
|
130 |
print(FilePath)
|
131 |
+
|
132 |
+
|
133 |
|
|
|
134 |
with open(FilePath, 'r', encoding="utf-8") as file_obj:
|
|
|
135 |
outputPath = os.path.join('F:/Desktop/test', FileName)
|
136 |
data = json.load(file_obj)
|
137 |
print("data:", data)
|
138 |
|
139 |
+
|
140 |
with open(outputPath, 'w', encoding="utf-8") as w:
|
141 |
json.dump(data, w, ensure_ascii=False, indent=4)
|
142 |
|
143 |
+
|
144 |
+
file_content = json.dumps(data)
|
145 |
+
url = "http://localhost:6222/submit"
|
146 |
files = {'file': (FileName, file_content, 'application/json')}
|
147 |
payload = {
|
148 |
'user_string': user_string,
|
|
|
152 |
|
153 |
response = requests.post(url, files=files, data=payload)
|
154 |
print(response)
|
155 |
+
|
156 |
if response.status_code == 200:
|
157 |
+
|
158 |
output_data = response.json()
|
159 |
|
160 |
+
|
161 |
+
output_file_path = os.path.join('/home/user/app/evaluate_result', 'new-model.json')
|
162 |
with open(output_file_path, 'w', encoding="utf-8") as f:
|
163 |
json.dump(output_data, f, ensure_ascii=False, indent=4)
|
164 |
|
165 |
print(f"File saved at: {output_file_path}")
|
166 |
|
167 |
+
|
168 |
+
directory_list = ['/home/user/app/dividing_into_different_subsets\5\QS']
|
169 |
+
file_list = ["calculate_humaneval_result.py"]
|
170 |
|
171 |
execute_specified_python_files(directory_list, file_list)
|
172 |
|
|
|
174 |
else:
|
175 |
return {"status": "error", "message": response.text}
|
176 |
|
177 |
+
|
178 |
return {"status": "success", "message": response.text}
|
179 |
|
180 |
def update_radio_options(token_counts, line_counts, cyclomatic_complexity, problem_type):
|
|
|
191 |
return gr.update(choices=options)
|
192 |
|
193 |
def plot_csv(radio,num):
|
194 |
+
|
|
|
195 |
if radio=="The Number of Tokens in Problem Descriptions":
|
196 |
radio_choice="token_counts"
|
197 |
+
file_path = f'/home/user/app/dividing_into_different_subsets/{num}/QS/{radio_choice}_QS.csv'
|
198 |
elif radio=="The Number of Lines in Problem Descriptions":
|
199 |
radio_choice="line_counts"
|
200 |
+
file_path = f'/home/user/app/dividing_into_different_subsets/{num}/QS/{radio_choice}_QS.csv'
|
201 |
elif radio=="The Complexity of Reference Code":
|
202 |
radio_choice="CC"
|
203 |
+
file_path = f'/home/user/app/dividing_into_different_subsets/{num}/QS/{radio_choice}_QS.csv'
|
204 |
elif radio=="Problem Type":
|
205 |
radio_choice="problem_type"
|
206 |
+
file_path = f'/home/user/app/dividing_into_different_subsets/cata_result.csv'
|
|
|
|
|
|
|
207 |
df = pd.read_csv(file_path)
|
|
|
208 |
df.set_index('Model', inplace=True)
|
209 |
|
|
|
210 |
df_transposed = df.T
|
|
|
|
|
211 |
fig = px.line(df_transposed, x=df_transposed.index, y=df_transposed.columns,
|
212 |
title='Model Evaluation Results',
|
213 |
labels={'value': 'Evaluation Score', 'index': 'Evaluation Metric'},
|
214 |
color_discrete_sequence=px.colors.qualitative.Plotly)
|
|
|
|
|
215 |
fig.update_traces(hovertemplate='%{y}')
|
216 |
|
217 |
return fig
|
218 |
|
219 |
|
|
|
|
|
220 |
import gradio as gr
|
221 |
|
222 |
with gr.Blocks() as iface:
|
|
|
336 |
outputs=json_output)
|
337 |
|
338 |
|
339 |
+
|
340 |
def toggle_radio(checkbox, radio):
|
341 |
return gr.update(visible=checkbox)
|
342 |
|
|
|
354 |
gr.HTML(f"<style>{css}</style>")
|
355 |
|
356 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
357 |
iface.launch()
|