-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
40 lines (37 loc) · 1.33 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<title>Codex – Code Execution GUI</title>
<script src="https://pyodide-cdn2.iodide.io/v0.15.0/full/pyodide.js"></script>
</head>
<body>
<div id='status'>
Loading pyodide..
</div>
<input type="text" id="input">
<div id="output"></div>
<script type="text/javascript">
// Give a more precise alias to this Promise object.
const pyodideLoader = languagePluginLoader
const t0 = Date.now()
const status_el = document.getElementById('status')
const input_el = document.getElementById("input")
const output_el = document.getElementById("output")
pyodideLoader.then(function () {
const dt = Math.round((Date.now() - t0) / 100) / 10
status_el.innerText += `done (${dt} s)`
const python_version_output = pyodide.runPython('import sys\nsys.version')
console.log(python_version_output)
input_el.addEventListener("input", (e) => {
const code_input = e.target.value
try {
const code_output = pyodide.runPython(code_input)
output_el.innerText = code_output
} catch (error) {
// fail silently
}
})
})
</script>
</body>
</html>