Athspi / templates /index.html
Artificial-superintelligence's picture
Update templates/index.html
a172f1d verified
raw
history blame
2.11 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Python Terminal</title>
<style>
/* Add terminal styling here */
</style>
</head>
<body>
<div class="terminal">
<div id="output" class="terminal-output">Python Terminal Ready...</div>
<div class="terminal-input">
<input type="text" id="code-input" placeholder="Enter Python code or !pip install package..." />
<button onclick="executeCode()">Run</button>
<button onclick="cleanup()">Cleanup</button>
</div>
</div>
<script>
function executeCode() {
const codeInput = document.getElementById("code-input");
const outputDiv = document.getElementById("output");
fetch("/execute", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ code: codeInput.value }),
})
.then(response => response.json())
.then(data => {
outputDiv.innerHTML += `\n> ${codeInput.value}\n${data.result}`;
outputDiv.scrollTop = outputDiv.scrollHeight; // Auto-scroll to bottom
codeInput.value = ""; // Clear input field
})
.catch(error => {
outputDiv.innerHTML += `\nError: ${error}`;
outputDiv.scrollTop = outputDiv.scrollHeight;
});
}
function cleanup() {
fetch("/cleanup", { method: "POST" })
.then(response => response.json())
.then(data => {
const outputDiv = document.getElementById("output");
outputDiv.innerHTML += `\n${data.result}`;
outputDiv.scrollTop = outputDiv.scrollHeight; // Auto-scroll to bottom
});
}
// Cleanup temporary files when the user leaves the page
window.addEventListener("beforeunload", cleanup);
</script>
</body>
</html>