-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_version.html
More file actions
97 lines (81 loc) · 3.67 KB
/
Copy pathpython_version.html
File metadata and controls
97 lines (81 loc) · 3.67 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Démonstration Python avec Wasmer</title>
<!-- Enable CORS-compliance for GH Pages-->
<script src="coi-serviceworker.js"></script>
<!-- Some Style -->
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<link rel="stylesheet" href="css/styles.css">
<link rel="stylesheet" href="css/green.css">
<script type="module">
// import { init, Wasmer } from 'https://unpkg.com/@wasmer/sdk@0.9.0/dist/index.mjs';
import { init, Wasmer } from './node_modules/@wasmer/sdk/dist/index.mjs';
let pythonPkg = null;
async function loadWasmerAndPython() {
const outputDiv = document.getElementById('output');
outputDiv.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Chargement de Wasmer et Python...';
try {
console.log("Initialisation de Wasmer...");
await init();
console.log("Wasmer initialisé");
console.log("Chargement du package Python...");
pythonPkg = await Wasmer.fromRegistry("python/python");
console.log("Package Python chargé");
outputDiv.innerHTML = `<i class="fas fa-check-circle"></i> Prêt à exécuter Python !`;
} catch (error) {
console.error("Erreur lors du chargement :", error);
outputDiv.innerHTML = `<i class="fas fa-bug"></i> Erreur de chargement : ${error.message}`;
}
}
async function runPythonDemo() {
const outputDiv = document.getElementById('output');
outputDiv.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Exécution en cours...';
try {
if (!pythonPkg) {
throw new Error("Le package Python n'est pas encore chargé.");
}
console.log("Exécution du code Python...");
const instance = await pythonPkg.entrypoint.run({
args: ["-V"]
});
console.log("Attente du résultat...");
const { code, stdout } = await instance.wait();
console.log(`Résultat obtenu: code ${code}, stdout: ${stdout}`);
outputDiv.innerHTML = `<i class="fas fa-check-circle"></i> ${stdout}`;
} catch (error) {
console.error("Erreur lors de l'exécution :", error);
outputDiv.innerHTML = `<i class="fas fa-bug"></i> Erreur : ${error.message}`;
}
}
document.addEventListener("DOMContentLoaded", () => {
check_isolated();
loadWasmerAndPython(); // Charge Wasmer & Python dès que la page est chargée
document.getElementById('runDemo').addEventListener('click', (e) => {
e.preventDefault();
runPythonDemo();
});
});
</script>
</head>
<body>
<header>
<h2><i class="fas fa-cogs"></i> Exécution de Python</h2>
<p>Cette démonstration exécute du code Python en utilisant Wasmer.</p>
</header>
<main>
<div id="output">
<i class="fas fa-spinner fa-spin"></i> Chargement...
</div>
<a href="#" class="btn" id="runDemo">
<i class="fas fa-play"></i> Exécuter la démo
</a>
</main>
<footer>
<p>© 2025 - Démo Wasmer & Python</p>
</footer>
</body>
</html>