Spaces:
Sleeping
Sleeping
Petr Tsvetkov
commited on
Commit
·
dfa91dd
1
Parent(s):
9589862
Separate form submission for each sample
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import os
|
|
| 2 |
import random
|
| 3 |
import uuid
|
| 4 |
from datetime import datetime
|
|
|
|
| 5 |
|
| 6 |
import gradio as gr
|
| 7 |
|
|
@@ -68,12 +69,18 @@ def update_commit_view(sample_ind):
|
|
| 68 |
|
| 69 |
commit_messages = tuple(record[model] for model in models_shuffled)
|
| 70 |
|
| 71 |
-
return (
|
|
|
|
|
|
|
| 72 |
models_shuffled)
|
| 73 |
|
| 74 |
|
| 75 |
def reset_answers():
|
| 76 |
-
return (None,) * (
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
|
| 79 |
def next_sample(current_sample_ind, shuffled_idx):
|
|
@@ -82,7 +89,7 @@ def next_sample(current_sample_ind, shuffled_idx):
|
|
| 82 |
|
| 83 |
current_sample_ind += 1
|
| 84 |
updated_view = update_commit_view(shuffled_idx[current_sample_ind])
|
| 85 |
-
return (current_sample_ind,) + updated_view + reset_answers()
|
| 86 |
|
| 87 |
|
| 88 |
with open("head.html") as head_file:
|
|
@@ -109,88 +116,102 @@ with gr.Blocks(theme=gr.themes.Soft(), head=head_html, css="style_overrides.css"
|
|
| 109 |
github_link = gr.Markdown()
|
| 110 |
diff_view = gr.HTML()
|
| 111 |
with gr.Column(scale=1):
|
| 112 |
-
commit_msg = []
|
| 113 |
-
is_correct = []
|
| 114 |
-
has_what = []
|
| 115 |
-
has_why = []
|
| 116 |
-
is_not_verbose = []
|
| 117 |
-
has_headline = []
|
| 118 |
-
easy_to_read = []
|
| 119 |
-
overall_rating = []
|
| 120 |
-
comments = []
|
| 121 |
-
model_name = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
SCALE = list(range(1, 6))
|
| 124 |
|
| 125 |
for model_ind in range(n_models):
|
| 126 |
with gr.Tab(f"Variant #{model_ind + 1}"):
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
gr.Markdown("## Please, rate your level of agreement with each statement\n"
|
| 131 |
"\n"
|
| 132 |
"*1 - strongly disagree, 2 - disagree, 3 - not sure, 4 - agree, 5 - strongly agree*")
|
| 133 |
|
| 134 |
-
|
|
|
|
|
|
|
| 135 |
info='The information provided in the commit message is consistent with the code changes.',
|
| 136 |
-
label=f'
|
| 137 |
show_label=False,
|
| 138 |
choices=SCALE,
|
| 139 |
interactive=True))
|
| 140 |
|
| 141 |
-
#
|
| 142 |
# info='The commit message answers the question of WHAT changes have been made.',
|
| 143 |
-
# label=f'
|
| 144 |
# show_label=False,
|
| 145 |
# choices=SCALE,
|
| 146 |
# interactive=True))
|
| 147 |
#
|
| 148 |
-
#
|
| 149 |
# info='The commit message answers the question of WHY these changes have been made.',
|
| 150 |
-
# label=f'
|
| 151 |
# show_label=False,
|
| 152 |
# choices=SCALE,
|
| 153 |
# interactive=True))
|
| 154 |
|
| 155 |
-
|
| 156 |
info='The commit message can be substantially shortened without loss of important information.',
|
| 157 |
-
label=f'
|
| 158 |
show_label=False,
|
| 159 |
choices=SCALE,
|
| 160 |
interactive=True))
|
| 161 |
|
| 162 |
-
#
|
| 163 |
# info='The commit message includes a short headline that provides a good overview of the '
|
| 164 |
# 'changes.',
|
| 165 |
-
# label=f'
|
| 166 |
# show_label=False,
|
| 167 |
# choices=SCALE,
|
| 168 |
# interactive=True))
|
| 169 |
|
| 170 |
-
|
| 171 |
info='The commit message is easy to read and to understand.',
|
| 172 |
-
label=f'
|
| 173 |
show_label=False,
|
| 174 |
choices=SCALE,
|
| 175 |
interactive=True))
|
| 176 |
|
| 177 |
-
|
| 178 |
info='Please, describe your overall impression of the commit message (1 - very bad, 5 - very '
|
| 179 |
'good)',
|
| 180 |
-
label=f'
|
| 181 |
show_label=False,
|
| 182 |
choices=SCALE,
|
| 183 |
interactive=True))
|
| 184 |
|
| 185 |
-
|
| 186 |
info='Additional comments on the commit message',
|
| 187 |
-
label=f'
|
| 188 |
show_label=False,
|
| 189 |
interactive=True))
|
| 190 |
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
-
submit_btn = gr.Button("Submit all and continue")
|
| 194 |
session_val = gr.Textbox(info='Session', interactive=False, container=True, show_label=False,
|
| 195 |
label='session')
|
| 196 |
|
|
@@ -208,8 +229,9 @@ with gr.Blocks(theme=gr.themes.Soft(), head=head_html, css="style_overrides.css"
|
|
| 208 |
repo_val,
|
| 209 |
hash_val,
|
| 210 |
sample_loaded_timestamp,
|
| 211 |
-
|
| 212 |
-
*
|
|
|
|
| 213 |
]
|
| 214 |
|
| 215 |
feedback_metadata = [
|
|
@@ -217,36 +239,38 @@ with gr.Blocks(theme=gr.themes.Soft(), head=head_html, css="style_overrides.css"
|
|
| 217 |
repo_val,
|
| 218 |
hash_val,
|
| 219 |
sample_loaded_timestamp,
|
| 220 |
-
sample_submitted_timestamp
|
| 221 |
-
*model_name
|
| 222 |
]
|
| 223 |
|
| 224 |
-
|
| 225 |
-
*is_correct,
|
| 226 |
-
# *has_what,
|
| 227 |
-
# *has_why,
|
| 228 |
-
*is_not_verbose,
|
| 229 |
-
# *has_headline,
|
| 230 |
-
*easy_to_read,
|
| 231 |
-
*overall_rating,
|
| 232 |
-
*comments
|
| 233 |
-
]
|
| 234 |
-
|
| 235 |
-
assert len(feedback_answers) == N_QUESTIONS * n_models
|
| 236 |
|
| 237 |
-
|
| 238 |
|
| 239 |
skip_btn.click(next_sample, inputs=[current_sample_sld, shuffled_idx_val],
|
| 240 |
-
outputs=[current_sample_sld] + commit_view +
|
| 241 |
|
|
|
|
|
|
|
| 242 |
|
| 243 |
-
def submit(current_sample, shuffled_idx, *args):
|
| 244 |
-
saver.flag((current_sample,) + args)
|
| 245 |
-
return next_sample(current_sample, shuffled_idx)
|
| 246 |
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
|
| 251 |
|
| 252 |
def init_session(current_sample):
|
|
|
|
| 2 |
import random
|
| 3 |
import uuid
|
| 4 |
from datetime import datetime
|
| 5 |
+
from itertools import chain
|
| 6 |
|
| 7 |
import gradio as gr
|
| 8 |
|
|
|
|
| 69 |
|
| 70 |
commit_messages = tuple(record[model] for model in models_shuffled)
|
| 71 |
|
| 72 |
+
return (
|
| 73 |
+
github_link_md, diff_view, repo_val, hash_val, diff_loaded_timestamp,
|
| 74 |
+
n_forms_submitted) + commit_messages + tuple(
|
| 75 |
models_shuffled)
|
| 76 |
|
| 77 |
|
| 78 |
def reset_answers():
|
| 79 |
+
return (None,) * (N_QUESTIONS * n_models)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def reset_submit_buttons():
|
| 83 |
+
return tuple(gr.Button(value="Submit", interactive=True) for _ in range(n_models))
|
| 84 |
|
| 85 |
|
| 86 |
def next_sample(current_sample_ind, shuffled_idx):
|
|
|
|
| 89 |
|
| 90 |
current_sample_ind += 1
|
| 91 |
updated_view = update_commit_view(shuffled_idx[current_sample_ind])
|
| 92 |
+
return (current_sample_ind,) + updated_view + reset_answers() + reset_submit_buttons()
|
| 93 |
|
| 94 |
|
| 95 |
with open("head.html") as head_file:
|
|
|
|
| 116 |
github_link = gr.Markdown()
|
| 117 |
diff_view = gr.HTML()
|
| 118 |
with gr.Column(scale=1):
|
| 119 |
+
# commit_msg = []
|
| 120 |
+
# is_correct = []
|
| 121 |
+
# # has_what = []
|
| 122 |
+
# # has_why = []
|
| 123 |
+
# is_not_verbose = []
|
| 124 |
+
# # has_headline = []
|
| 125 |
+
# easy_to_read = []
|
| 126 |
+
# overall_rating = []
|
| 127 |
+
# comments = []
|
| 128 |
+
# model_name = []
|
| 129 |
+
|
| 130 |
+
commit_msgs = []
|
| 131 |
+
questions = []
|
| 132 |
+
model_names = []
|
| 133 |
+
submit_buttons = []
|
| 134 |
|
| 135 |
SCALE = list(range(1, 6))
|
| 136 |
|
| 137 |
for model_ind in range(n_models):
|
| 138 |
with gr.Tab(f"Variant #{model_ind + 1}"):
|
| 139 |
+
commit_msgs.append(gr.TextArea(label="Commit message (can be scrollable)",
|
| 140 |
+
interactive=False,
|
| 141 |
+
))
|
| 142 |
gr.Markdown("## Please, rate your level of agreement with each statement\n"
|
| 143 |
"\n"
|
| 144 |
"*1 - strongly disagree, 2 - disagree, 3 - not sure, 4 - agree, 5 - strongly agree*")
|
| 145 |
|
| 146 |
+
model_questions = []
|
| 147 |
+
|
| 148 |
+
model_questions.append(gr.Radio(
|
| 149 |
info='The information provided in the commit message is consistent with the code changes.',
|
| 150 |
+
label=f'is_correct',
|
| 151 |
show_label=False,
|
| 152 |
choices=SCALE,
|
| 153 |
interactive=True))
|
| 154 |
|
| 155 |
+
# model_questions.append(gr.Radio(
|
| 156 |
# info='The commit message answers the question of WHAT changes have been made.',
|
| 157 |
+
# label=f'has_what',
|
| 158 |
# show_label=False,
|
| 159 |
# choices=SCALE,
|
| 160 |
# interactive=True))
|
| 161 |
#
|
| 162 |
+
# model_questions.append(gr.Radio(
|
| 163 |
# info='The commit message answers the question of WHY these changes have been made.',
|
| 164 |
+
# label=f'has_why',
|
| 165 |
# show_label=False,
|
| 166 |
# choices=SCALE,
|
| 167 |
# interactive=True))
|
| 168 |
|
| 169 |
+
model_questions.append(gr.Radio(
|
| 170 |
info='The commit message can be substantially shortened without loss of important information.',
|
| 171 |
+
label=f'is_not_verbose',
|
| 172 |
show_label=False,
|
| 173 |
choices=SCALE,
|
| 174 |
interactive=True))
|
| 175 |
|
| 176 |
+
# model_questions.append(gr.Radio(
|
| 177 |
# info='The commit message includes a short headline that provides a good overview of the '
|
| 178 |
# 'changes.',
|
| 179 |
+
# label=f'has_headline',
|
| 180 |
# show_label=False,
|
| 181 |
# choices=SCALE,
|
| 182 |
# interactive=True))
|
| 183 |
|
| 184 |
+
model_questions.append(gr.Radio(
|
| 185 |
info='The commit message is easy to read and to understand.',
|
| 186 |
+
label=f'easy_to_read',
|
| 187 |
show_label=False,
|
| 188 |
choices=SCALE,
|
| 189 |
interactive=True))
|
| 190 |
|
| 191 |
+
model_questions.append(gr.Radio(
|
| 192 |
info='Please, describe your overall impression of the commit message (1 - very bad, 5 - very '
|
| 193 |
'good)',
|
| 194 |
+
label=f'overall_rating',
|
| 195 |
show_label=False,
|
| 196 |
choices=SCALE,
|
| 197 |
interactive=True))
|
| 198 |
|
| 199 |
+
model_questions.append(gr.Textbox(
|
| 200 |
info='Additional comments on the commit message',
|
| 201 |
+
label=f'comments',
|
| 202 |
show_label=False,
|
| 203 |
interactive=True))
|
| 204 |
|
| 205 |
+
assert len(model_questions) == N_QUESTIONS
|
| 206 |
+
|
| 207 |
+
questions.append(model_questions)
|
| 208 |
+
model_names.append(gr.Textbox(interactive=False, label=f'model', visible=False))
|
| 209 |
+
|
| 210 |
+
submit_buttons.append(gr.Button(value="Submit"))
|
| 211 |
+
|
| 212 |
+
n_forms_submitted = gr.Number(visible=False, value=0, precision=0)
|
| 213 |
+
continue_btn = gr.Button(value=f"0/{n_models} forms submitted", interactive=False)
|
| 214 |
|
|
|
|
| 215 |
session_val = gr.Textbox(info='Session', interactive=False, container=True, show_label=False,
|
| 216 |
label='session')
|
| 217 |
|
|
|
|
| 229 |
repo_val,
|
| 230 |
hash_val,
|
| 231 |
sample_loaded_timestamp,
|
| 232 |
+
n_forms_submitted,
|
| 233 |
+
*commit_msgs,
|
| 234 |
+
*model_names,
|
| 235 |
]
|
| 236 |
|
| 237 |
feedback_metadata = [
|
|
|
|
| 239 |
repo_val,
|
| 240 |
hash_val,
|
| 241 |
sample_loaded_timestamp,
|
| 242 |
+
sample_submitted_timestamp
|
|
|
|
| 243 |
]
|
| 244 |
|
| 245 |
+
saver.setup([current_sample_sld] + feedback_metadata + questions[0] + [model_names[0], ], "feedback")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
|
| 247 |
+
questions_list = list(chain.from_iterable(questions))
|
| 248 |
|
| 249 |
skip_btn.click(next_sample, inputs=[current_sample_sld, shuffled_idx_val],
|
| 250 |
+
outputs=[current_sample_sld] + commit_view + questions_list + submit_buttons)
|
| 251 |
|
| 252 |
+
continue_btn.click(next_sample, inputs=[current_sample_sld, shuffled_idx_val],
|
| 253 |
+
outputs=[current_sample_sld] + commit_view + questions_list + submit_buttons)
|
| 254 |
|
|
|
|
|
|
|
|
|
|
| 255 |
|
| 256 |
+
def submit_for_model(current_sample, n_forms_submitted_val, *args):
|
| 257 |
+
saver.flag((current_sample,) + args)
|
| 258 |
+
n_forms_submitted_val += 1
|
| 259 |
+
all_forms_submitted = n_forms_submitted_val == n_models
|
| 260 |
+
return (gr.Button(value="Submitted", interactive=False),
|
| 261 |
+
n_forms_submitted_val,
|
| 262 |
+
gr.Button(
|
| 263 |
+
"Next sample" if all_forms_submitted else f"{n_forms_submitted_val}/{n_models} forms submitted",
|
| 264 |
+
interactive=all_forms_submitted))
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
for model_ind in range(n_models):
|
| 268 |
+
submit_buttons[model_ind].click(
|
| 269 |
+
submit_for_model,
|
| 270 |
+
inputs=[current_sample_sld, n_forms_submitted] + feedback_metadata + questions[model_ind] + [
|
| 271 |
+
model_names[model_ind], ],
|
| 272 |
+
outputs=[submit_buttons[model_ind], n_forms_submitted, continue_btn]
|
| 273 |
+
)
|
| 274 |
|
| 275 |
|
| 276 |
def init_session(current_sample):
|