File size: 1,515 Bytes
63912b1
 
 
d86b3b9
63912b1
d86b3b9
63912b1
 
 
613b59c
 
 
 
 
63912b1
 
 
 
 
d86b3b9
63912b1
 
 
d86b3b9
a4bf183
 
63912b1
a4bf183
63912b1
a4bf183
63912b1
a4bf183
 
 
613b59c
 
 
a4bf183
613b59c
d86b3b9
63912b1
613b59c
 
63912b1
 
 
 
 
 
a4bf183
613b59c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<div style="padding-bottom: 20px;">
  <div id="trl_diff" style="width: 100%; height: 400px; border: 1px solid grey;"></div>
</div>

<script src="https://unpkg.com/monaco-editor@latest/min/vs/loader.js"></script>
<script>
  const proxy = URL.createObjectURL(
    new Blob(
      [`
        self.MonacoEnvironment = {
          baseUrl: 'https://unpkg.com/monaco-editor@latest/min/'
        };
        importScripts('https://unpkg.com/monaco-editor@latest/min/vs/base/worker/workerMain.js');
      `],
      { type: "text/javascript" }
    )
  );

  window.MonacoEnvironment = { getWorkerUrl: () => proxy };

  require.config({
    paths: { vs: "https://unpkg.com/monaco-editor@latest/min/vs" }
  });

  let diffEditor;

  require(["vs/editor/editor.main"], function () {
    diffEditor = monaco.editor.createDiffEditor(
      document.getElementById("trl_diff"),
      { readOnly: true, automaticLayout: true }
    );
    loadDiff();
  });

  const ORIGINAL_URL = "https://trl-lib-diff-view.static.hf.space/grpo_trainer.py";
  const MODIFIED_URL = "https://trl-lib-diff-view.static.hf.space/rloo_trainer.py";

  function loadDiff() {
    if (!diffEditor) return;

    Promise.all([
      fetch(ORIGINAL_URL).then(r => r.text()),
      fetch(MODIFIED_URL).then(r => r.text())
    ]).then(([originalTxt, modifiedTxt]) => {
      diffEditor.setModel({
        original: monaco.editor.createModel(originalTxt, "python"),
        modified: monaco.editor.createModel(modifiedTxt, "python")
      });
    });
  }
</script>