Petr Tsvetkov commited on
Commit
0b259d2
β€’
1 Parent(s): a8a595d

Fix the visualization

Browse files
Files changed (1) hide show
  1. change_visualizer.py +28 -40
change_visualizer.py CHANGED
@@ -13,7 +13,7 @@ STATISTICS = {"manual": statistics.get_statistics_for_manual_df(df_manual),
13
  "synthetic": statistics.get_statistics_for_synthetic_df(df_synthetic)}
14
 
15
 
16
- def update_manual_view(diff_idx):
17
  diff_idx -= 1
18
  return df_manual.iloc[diff_idx]['annotated_diff'], df_manual.iloc[diff_idx]['commit_msg_start'], \
19
  df_manual.iloc[diff_idx][
@@ -21,13 +21,6 @@ def update_manual_view(diff_idx):
21
  'session'], f"https://github.com/{df_manual.iloc[diff_idx]['repo']}/commit/{df_manual.iloc[diff_idx]['hash']}"
22
 
23
 
24
- def update_synthetic_view(diff_idx):
25
- diff_idx -= 1
26
- return (df_synthetic.iloc[diff_idx]['annotated_diff'], df_synthetic.iloc[diff_idx]['initial_msg_pred'],
27
- df_synthetic.iloc[diff_idx]['reference'],
28
- f"https://github.com/{df_synthetic.iloc[diff_idx]['repo']}/commit/{df_synthetic.iloc[diff_idx]['hash']}")
29
-
30
-
31
  force_light_theme_js_func = """
32
  function refresh() {
33
  const url = new URL(window.location);
@@ -41,42 +34,37 @@ function refresh() {
41
 
42
  if __name__ == '__main__':
43
  with gr.Blocks(theme=gr.themes.Soft(), js=force_light_theme_js_func) as application:
44
- with gr.Tab("Manual"):
45
- slider_manual = gr.Slider(minimum=1, maximum=n_diffs_manual, step=1, value=1,
46
- label=f"Sample number (total: {n_diffs_manual})")
47
-
48
- diff_view_manual = gr.Highlightedtext(combine_adjacent=True, color_map={'+': "green", '-': "red"})
49
- start_view_manual = gr.Textbox(interactive=False, label="Start message", container=True)
50
- end_view_manual = gr.Textbox(interactive=False, label="End message", container=True)
51
- session_view_manual = gr.Textbox(interactive=False, label="Session", container=True)
52
- link_view_manual = gr.Markdown()
53
- view_manual = [
54
- diff_view_manual,
55
- start_view_manual,
56
- end_view_manual,
57
- session_view_manual,
58
- link_view_manual
 
59
  ]
60
 
61
- slider_manual.change(update_manual_view, inputs=slider_manual,
 
 
 
 
 
 
62
  outputs=view_manual)
63
 
64
  with gr.Tab("Synthetic"):
65
- slider_synthetic = gr.Slider(minimum=1, maximum=n_diffs_synthetic, step=1, value=1,
66
- label=f"Sample number (total: {n_diffs_synthetic})")
67
-
68
- diff_view_synthetic = gr.Highlightedtext(combine_adjacent=True, color_map={'+': "green", '-': "red"})
69
- start_view_synthetic = gr.Textbox(interactive=False, label="Start message", container=True)
70
- end_view_synthetic = gr.Textbox(interactive=False, label="End message", container=True)
71
- link_view_synthetic = gr.Markdown()
72
- view_synthetic = [
73
- diff_view_synthetic,
74
- start_view_synthetic,
75
- end_view_synthetic,
76
- link_view_synthetic
77
- ]
78
 
79
- slider_synthetic.change(update_synthetic_view, inputs=slider_synthetic,
80
  outputs=view_synthetic)
81
  with gr.Tab("Compare"):
82
  def layout_for_statistics(statistics_group_name):
@@ -97,10 +85,10 @@ if __name__ == '__main__':
97
  with gr.Column(scale=1):
98
  layout_for_statistics("synthetic")
99
 
100
- application.load(update_manual_view, inputs=slider_manual,
101
  outputs=view_manual)
102
 
103
- application.load(update_synthetic_view, inputs=slider_synthetic,
104
  outputs=view_synthetic)
105
 
106
  application.launch()
 
13
  "synthetic": statistics.get_statistics_for_synthetic_df(df_synthetic)}
14
 
15
 
16
+ def update_dataset_view(diff_idx):
17
  diff_idx -= 1
18
  return df_manual.iloc[diff_idx]['annotated_diff'], df_manual.iloc[diff_idx]['commit_msg_start'], \
19
  df_manual.iloc[diff_idx][
 
21
  'session'], f"https://github.com/{df_manual.iloc[diff_idx]['repo']}/commit/{df_manual.iloc[diff_idx]['hash']}"
22
 
23
 
 
 
 
 
 
 
 
24
  force_light_theme_js_func = """
25
  function refresh() {
26
  const url = new URL(window.location);
 
34
 
35
  if __name__ == '__main__':
36
  with gr.Blocks(theme=gr.themes.Soft(), js=force_light_theme_js_func) as application:
37
+ def dataset_view_tab(n_items):
38
+ slider = gr.Slider(minimum=1, maximum=n_items, step=1, value=1,
39
+ label=f"Sample number (total: {n_items})")
40
+
41
+ diff_view = gr.Highlightedtext(combine_adjacent=True, color_map={'+': "green", '-': "red"})
42
+ start_view = gr.Textbox(interactive=False, label="Start message", container=True)
43
+ end_view = gr.Textbox(interactive=False, label="End message", container=True)
44
+ session_view = gr.Textbox(interactive=False, label="Session", container=True)
45
+ link_view = gr.Markdown()
46
+
47
+ view = [
48
+ diff_view,
49
+ start_view,
50
+ end_view,
51
+ session_view,
52
+ link_view
53
  ]
54
 
55
+ return slider, view
56
+
57
+
58
+ with gr.Tab("Manual"):
59
+ slider_manual, view_manual = dataset_view_tab(n_diffs_manual)
60
+
61
+ slider_manual.change(update_dataset_view, inputs=slider_manual,
62
  outputs=view_manual)
63
 
64
  with gr.Tab("Synthetic"):
65
+ slider_synthetic, view_synthetic = dataset_view_tab(n_diffs_synthetic)
 
 
 
 
 
 
 
 
 
 
 
 
66
 
67
+ slider_synthetic.change(update_dataset_view, inputs=slider_synthetic,
68
  outputs=view_synthetic)
69
  with gr.Tab("Compare"):
70
  def layout_for_statistics(statistics_group_name):
 
85
  with gr.Column(scale=1):
86
  layout_for_statistics("synthetic")
87
 
88
+ application.load(update_dataset_view, inputs=slider_manual,
89
  outputs=view_manual)
90
 
91
+ application.load(update_dataset_view, inputs=slider_synthetic,
92
  outputs=view_synthetic)
93
 
94
  application.launch()