Petr Tsvetkov commited on
Commit
815e7fc
·
1 Parent(s): 14bb44e

Display multiple versions of a commit message

Browse files
Files changed (1) hide show
  1. app.py +117 -96
app.py CHANGED
@@ -4,17 +4,16 @@ import random
4
  import uuid
5
 
6
  import gradio as gr
7
- from datasets import load_dataset
 
8
 
9
  HF_TOKEN = os.environ.get('HF_TOKEN')
10
  HF_DATASET = os.environ.get('HF_DATASET')
11
 
12
- configuration = "commitchronicle-py-long" # select a configuration
13
- dataset = load_dataset("JetBrains-Research/lca-cmg",
14
- configuration,
15
- split="test",
16
- cache_dir="data")
17
- n_samples = len(dataset)
18
 
19
  saver = gr.HuggingFaceDatasetSaver(HF_TOKEN, HF_DATASET, private=True)
20
 
@@ -34,7 +33,7 @@ def convert_diff_to_unified(diff):
34
 
35
  def get_diff2html_view(raw_diff):
36
  html = f"""
37
- <div style='width:100%; height:720px; overflow:auto; position: relative'>
38
  <div id='diff-raw' hidden>{raw_diff}</div>
39
  <div class="d2h-view-wrapper">
40
  <div id='diff-view'></div>
@@ -49,14 +48,19 @@ def update_commit_view(sample_ind):
49
  if sample_ind >= n_samples:
50
  return None
51
 
52
- record = dataset[sample_ind]
53
 
54
  diff_view = get_diff2html_view(convert_diff_to_unified(record['mods']))
55
- commit_msg = record['message']
56
  repo_val = record['repo']
57
  hash_val = record['hash']
58
  diff_loaded_timestamp = datetime.now().isoformat()
59
- return diff_view, commit_msg, repo_val, hash_val, diff_loaded_timestamp
 
 
 
 
 
 
60
 
61
 
62
  def next_sample(current_sample_ind, shuffled_idx):
@@ -91,81 +95,96 @@ with gr.Blocks(theme=gr.themes.Soft(), head=head_html, css="style_overrides.css"
91
  with gr.Column(scale=2):
92
  diff_view = gr.HTML()
93
  with gr.Column(scale=1):
94
- commit_msg = gr.Textbox(label="Commit message",
95
- interactive=False,
96
- )
97
- gr.Markdown("## Please, rate your level of agreement with each statement\n"
98
- "\n"
99
- "*1 - strongly disagree, 2 - disagree, 3 - agree, 4 - strongly agree*")
100
-
101
- is_correct = gr.Slider(
102
- info='The information provided in the commit message is consistent with the code changes.',
103
- label='is_correct',
104
- show_label=False,
105
- minimum=1,
106
- step=1,
107
- interactive=True,
108
- maximum=4)
109
-
110
- has_what = gr.Slider(
111
- info='The commit message answers the question of WHAT changes have been made.',
112
- label='has_what',
113
- show_label=False,
114
- minimum=1,
115
- step=1,
116
- interactive=True,
117
- maximum=4)
118
-
119
- has_why = gr.Slider(
120
- info='The commit message answers the question of WHY these changes have been made.',
121
- label='has_why',
122
- show_label=False,
123
- minimum=1,
124
- step=1,
125
- interactive=True,
126
- maximum=4)
127
-
128
- is_not_verbose = gr.Slider(
129
- info='The commit message can be substantially shortened without loss of important information.',
130
- label='is_not_verbose',
131
- show_label=False,
132
- minimum=1,
133
- step=1,
134
- interactive=True,
135
- maximum=4)
136
-
137
- has_headline = gr.Slider(
138
- info='The commit message includes a short headline that provides a good overview of the changes.',
139
- label='has_headline',
140
- show_label=False,
141
- minimum=1,
142
- step=1,
143
- interactive=True,
144
- maximum=4)
145
-
146
- easy_to_read = gr.Slider(
147
- info='The commit message is easy to read and to understand.',
148
- label='easy_to_read',
149
- show_label=False,
150
- minimum=1,
151
- step=1,
152
- interactive=True,
153
- maximum=4)
154
-
155
- overall_rating = gr.Slider(
156
- info='Please, describe your overall impression of the commit message (1 - very bad, 5 - very good)',
157
- label='overall_rating',
158
- show_label=False,
159
- minimum=1,
160
- step=1,
161
- interactive=True,
162
- maximum=5)
163
-
164
- comments = gr.Textbox(
165
- info='Additional comments on the commit message',
166
- label='comments',
167
- show_label=False,
168
- interactive=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
 
170
  submit_btn = gr.Button("Submit and continue")
171
  session_val = gr.Textbox(info='Session', interactive=False, container=True, show_label=False,
@@ -181,10 +200,11 @@ with gr.Blocks(theme=gr.themes.Soft(), head=head_html, css="style_overrides.css"
181
 
182
  commit_view = [
183
  diff_view,
184
- commit_msg,
185
  repo_val,
186
  hash_val,
187
- sample_loaded_timestamp
 
 
188
  ]
189
 
190
  feedback_form = [
@@ -193,14 +213,15 @@ with gr.Blocks(theme=gr.themes.Soft(), head=head_html, css="style_overrides.css"
193
  hash_val,
194
  sample_loaded_timestamp,
195
  sample_submitted_timestamp,
196
- is_correct,
197
- has_what,
198
- has_why,
199
- is_not_verbose,
200
- has_headline,
201
- easy_to_read,
202
- overall_rating,
203
- comments
 
204
  ]
205
 
206
  saver.setup([current_sample_sld] + feedback_form, "feedback")
 
4
  import uuid
5
 
6
  import gradio as gr
7
+
8
+ from data_loader import load_data
9
 
10
  HF_TOKEN = os.environ.get('HF_TOKEN')
11
  HF_DATASET = os.environ.get('HF_DATASET')
12
 
13
+ data, models = load_data()
14
+
15
+ n_samples = len(data)
16
+ n_models = len(models)
 
 
17
 
18
  saver = gr.HuggingFaceDatasetSaver(HF_TOKEN, HF_DATASET, private=True)
19
 
 
33
 
34
  def get_diff2html_view(raw_diff):
35
  html = f"""
36
+ <div style='width:100%; height:1400px; overflow:auto; position: relative'>
37
  <div id='diff-raw' hidden>{raw_diff}</div>
38
  <div class="d2h-view-wrapper">
39
  <div id='diff-view'></div>
 
48
  if sample_ind >= n_samples:
49
  return None
50
 
51
+ record = data[sample_ind]
52
 
53
  diff_view = get_diff2html_view(convert_diff_to_unified(record['mods']))
 
54
  repo_val = record['repo']
55
  hash_val = record['hash']
56
  diff_loaded_timestamp = datetime.now().isoformat()
57
+
58
+ models_shuffled = models[:]
59
+ random.shuffle(models_shuffled)
60
+
61
+ commit_messages = tuple(record[model] for model in models_shuffled)
62
+
63
+ return (diff_view, repo_val, hash_val, diff_loaded_timestamp) + commit_messages + tuple(models_shuffled)
64
 
65
 
66
  def next_sample(current_sample_ind, shuffled_idx):
 
95
  with gr.Column(scale=2):
96
  diff_view = gr.HTML()
97
  with gr.Column(scale=1):
98
+ commit_msg = []
99
+ is_correct = []
100
+ has_what = []
101
+ has_why = []
102
+ is_not_verbose = []
103
+ has_headline = []
104
+ easy_to_read = []
105
+ overall_rating = []
106
+ comments = []
107
+ model_name = []
108
+
109
+ for model_ind in range(n_models):
110
+ with gr.Tab(f"Message #{model_ind + 1}"):
111
+ commit_msg.append(gr.TextArea(label="Commit message (can be scrollable)",
112
+ interactive=False,
113
+ ))
114
+ gr.Markdown("## Please, rate your level of agreement with each statement\n"
115
+ "\n"
116
+ "*1 - strongly disagree, 2 - disagree, 3 - agree, 4 - strongly agree*")
117
+
118
+ is_correct.append(gr.Slider(
119
+ info='The information provided in the commit message is consistent with the code changes.',
120
+ label=f'is_correct_{model_ind}',
121
+ show_label=False,
122
+ minimum=1,
123
+ step=1,
124
+ interactive=True,
125
+ maximum=4))
126
+
127
+ has_what.append(gr.Slider(
128
+ info='The commit message answers the question of WHAT changes have been made.',
129
+ label=f'has_what_{model_ind}',
130
+ show_label=False,
131
+ minimum=1,
132
+ step=1,
133
+ interactive=True,
134
+ maximum=4))
135
+
136
+ has_why.append(gr.Slider(
137
+ info='The commit message answers the question of WHY these changes have been made.',
138
+ label=f'has_why_{model_ind}',
139
+ show_label=False,
140
+ minimum=1,
141
+ step=1,
142
+ interactive=True,
143
+ maximum=4))
144
+
145
+ is_not_verbose.append(gr.Slider(
146
+ info='The commit message can be substantially shortened without loss of important information.',
147
+ label=f'is_not_verbose_{model_ind}',
148
+ show_label=False,
149
+ minimum=1,
150
+ step=1,
151
+ interactive=True,
152
+ maximum=4))
153
+
154
+ has_headline.append(gr.Slider(
155
+ info='The commit message includes a short headline that provides a good overview of the changes.',
156
+ label=f'has_headline_{model_ind}',
157
+ show_label=False,
158
+ minimum=1,
159
+ step=1,
160
+ interactive=True,
161
+ maximum=4))
162
+
163
+ easy_to_read.append(gr.Slider(
164
+ info='The commit message is easy to read and to understand.',
165
+ label=f'easy_to_read_{model_ind}',
166
+ show_label=False,
167
+ minimum=1,
168
+ step=1,
169
+ interactive=True,
170
+ maximum=4))
171
+
172
+ overall_rating.append(gr.Slider(
173
+ info='Please, describe your overall impression of the commit message (1 - very bad, 5 - very good)',
174
+ label=f'overall_rating_{model_ind}',
175
+ show_label=False,
176
+ minimum=1,
177
+ step=1,
178
+ interactive=True,
179
+ maximum=5))
180
+
181
+ comments.append(gr.Textbox(
182
+ info='Additional comments on the commit message',
183
+ label=f'comments_{model_ind}',
184
+ show_label=False,
185
+ interactive=True))
186
+
187
+ model_name.append(gr.Textbox(interactive=False, label=f'model_{model_ind}', visible=False))
188
 
189
  submit_btn = gr.Button("Submit and continue")
190
  session_val = gr.Textbox(info='Session', interactive=False, container=True, show_label=False,
 
200
 
201
  commit_view = [
202
  diff_view,
 
203
  repo_val,
204
  hash_val,
205
+ sample_loaded_timestamp,
206
+ *commit_msg,
207
+ *model_name
208
  ]
209
 
210
  feedback_form = [
 
213
  hash_val,
214
  sample_loaded_timestamp,
215
  sample_submitted_timestamp,
216
+ *is_correct,
217
+ *has_what,
218
+ *has_why,
219
+ *is_not_verbose,
220
+ *has_headline,
221
+ *easy_to_read,
222
+ *overall_rating,
223
+ *comments,
224
+ *model_name
225
  ]
226
 
227
  saver.setup([current_sample_sld] + feedback_form, "feedback")