Petr Tsvetkov commited on
Commit
0958c91
·
1 Parent(s): 7af62b1

Add diff2html iframe to commit view

Browse files

The commit view has been updated to use an iframe showing a diff2html view of each commit link. Also submission bug fixed

Files changed (1) hide show
  1. app.py +37 -6
app.py CHANGED
@@ -19,17 +19,48 @@ def get_github_link(repo, hash):
19
  return repo_url
20
 
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  def update_commit_view(sample_ind):
23
  if sample_ind >= n_samples:
24
  return None
25
 
26
  record = dataset[sample_ind]
27
- github_link_md = f"[See the commit on GitHub]({get_github_link(record['repo'], record['hash'])})"
28
- diff_json = record['mods']
 
 
29
  commit_msg = record['message']
30
  repo_val = record['repo']
31
  hash_val = record['hash']
32
- return github_link_md, diff_json, commit_msg, repo_val, hash_val
33
 
34
 
35
  def next_sample(current_sample_ind, shuffled_idx):
@@ -60,7 +91,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
60
  with gr.Row():
61
  with gr.Column(scale=2):
62
  github_link = gr.Markdown()
63
- diff_view = gr.JSON()
64
  with gr.Column(scale=1):
65
  commit_msg = gr.Textbox(label="AI-generated commit message",
66
  interactive=False,
@@ -107,14 +138,14 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
107
  format_feedback
108
  ]
109
 
110
- saver.setup(feedback_form, "feedback")
111
 
112
  skip_btn.click(next_sample, inputs=[current_sample_sld, shuffled_idx_val],
113
  outputs=[current_sample_sld] + commit_view)
114
 
115
 
116
  def submit(current_sample, shuffled_idx, *args):
117
- saver.flag([current_sample] + args)
118
  return next_sample(current_sample, shuffled_idx)
119
 
120
 
 
19
  return repo_url
20
 
21
 
22
+ def get_diff2html_demo_iframe(github_link):
23
+ diff2html_link = (f"https://diff2html.xyz/demo.html?matching=none"
24
+ f"&matchWordsThreshold=0.25"
25
+ f"&maxLineLengthHighlight=10000"
26
+ f"&diffStyle=word"
27
+ f"&colorScheme=light"
28
+ f"&renderNothingWhenEmpty=0"
29
+ f"&matchingMaxComparisons=2500"
30
+ f"&maxLineSizeInBlockForComparison=200"
31
+ f"&outputFormat=line-by-line"
32
+ f"&drawFileList=1&synchronisedScroll=1"
33
+ f"&highlight=1"
34
+ f"&fileListToggle=1"
35
+ f"&fileListStartVisible=0"
36
+ f"&highlightLanguages=[object%20Map]"
37
+ f"&smartSelection=1"
38
+ f"&fileContentToggle=1"
39
+ f"&stickyFileHeaders=1"
40
+ f"&diff={github_link}")
41
+
42
+ iframe_html = (f"<iframe "
43
+ f"src=\"{diff2html_link}\" "
44
+ f"title=\"diff2html Demo Diff Viewer\" "
45
+ f"style='width:100%; height:720px; overflow:auto'>"
46
+ f"</iframe>")
47
+
48
+ return iframe_html
49
+
50
+
51
  def update_commit_view(sample_ind):
52
  if sample_ind >= n_samples:
53
  return None
54
 
55
  record = dataset[sample_ind]
56
+ github_link = get_github_link(record['repo'], record['hash'])
57
+
58
+ github_link_md = f"[See the commit on GitHub]({github_link})"
59
+ diff_view = get_diff2html_demo_iframe(github_link)
60
  commit_msg = record['message']
61
  repo_val = record['repo']
62
  hash_val = record['hash']
63
+ return github_link_md, diff_view, commit_msg, repo_val, hash_val
64
 
65
 
66
  def next_sample(current_sample_ind, shuffled_idx):
 
91
  with gr.Row():
92
  with gr.Column(scale=2):
93
  github_link = gr.Markdown()
94
+ diff_view = gr.HTML()
95
  with gr.Column(scale=1):
96
  commit_msg = gr.Textbox(label="AI-generated commit message",
97
  interactive=False,
 
138
  format_feedback
139
  ]
140
 
141
+ saver.setup([current_sample_sld] + feedback_form, "feedback")
142
 
143
  skip_btn.click(next_sample, inputs=[current_sample_sld, shuffled_idx_val],
144
  outputs=[current_sample_sld] + commit_view)
145
 
146
 
147
  def submit(current_sample, shuffled_idx, *args):
148
+ saver.flag((current_sample,) + args)
149
  return next_sample(current_sample, shuffled_idx)
150
 
151