CoolFace
Apppublic

admin08077/javascript-python

sourceHugging Facemitupdated 2y agoView on Hugging Face
1likes
index.html38 linesDownload Raw Back to root
1<!DOCTYPE html>2<html lang="en">3<head>4    <meta charset="UTF-8">5    <title>Pyodide Example</title>6    <script src="https://cdn.jsdelivr.net/pyodide/v0.23.4/full/pyodide.js"></script>7</head>8<body>9    <textarea id="python-code" rows="10" cols="50">10# Sample Python Code11import math12 13def compute_circle_area(radius):14    return math.pi * radius ** 215 16print(compute_circle_area(5))17    </textarea>18    <br>19    <button onclick="runPython()">Run Python</button>20    <pre id="output"></pre>21 22    <script>23        let pyodideReadyPromise = loadPyodide();24 25        async function runPython() {26            await pyodideReadyPromise;27            const code = document.getElementById("python-code").value;28            try {29                let output = await pyodide.runPythonAsync(code);30                document.getElementById("output").textContent = output;31            } catch (err) {32                document.getElementById("output").textContent = err;33            }34        }35    </script>36</body>37</html>38