compute_pool / templates /index.html
Oscar Wang
Update templates/index.html
2ffe902 verified
raw
history blame
3.94 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>File Upload and Command Execution</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet">
<script>
async function handleUpload(event) {
event.preventDefault();
let formData = new FormData(document.getElementById('uploadForm'));
let response = await fetch('/upload', {
method: 'POST',
body: formData
});
let result = await response.json();
document.getElementById('uploadStatus').innerText = result.message || '';
if (result.download_url) {
document.getElementById('downloadLink').href = result.download_url;
document.getElementById('downloadLink').style.display = 'inline';
}
}
async function executeCommand(event) {
event.preventDefault();
let formData = new FormData();
formData.append('command', document.getElementById('commandInput').value);
let response = await fetch('/execute_command', {
method: 'POST',
body: formData
});
let result = await response.json();
document.getElementById('commandOutput').innerText = result.log_output || '';
}
async function refreshCpuInfo() {
let response = await fetch('/cpu_info');
let result = await response.json();
document.getElementById('cpuInfo').innerText = result.cpu_info || '';
}
setInterval(refreshCpuInfo, 2000);
</script>
</head>
<body class="bg-gray-100 flex flex-col items-center justify-center min-h-screen py-6">
<div class="w-full max-w-4xl bg-white p-6 rounded-lg shadow-lg">
<h1 class="text-2xl font-bold mb-4">Upload Files and Run Python Code</h1>
<form id="uploadForm" class="space-y-4" onsubmit="handleUpload(event)">
<div>
<label class="block text-sm font-medium text-gray-700">Upload Files:</label>
<input type="file" name="file" multiple class="mt-1 block w-full border-gray-300 rounded-md shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" />
</div>
<div>
<label class="block text-sm font-medium text-gray-700">Python Script:</label>
<textarea name="script_content" rows="6" class="mt-1 block w-full border-gray-300 rounded-md shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"></textarea>
</div>
<button type="submit" class="mt-4 px-4 py-2 bg-indigo-600 text-white font-semibold rounded-lg shadow-md hover:bg-indigo-700">Run Script</button>
<p id="uploadStatus" class="mt-2 text-red-600"></p>
<a id="downloadLink" href="#" class="mt-4 text-indigo-600" style="display:none">Download Output</a>
</form>
<h2 class="text-xl font-bold mt-8">Execute Commands</h2>
<form id="commandForm" class="space-y-4 mt-4" onsubmit="executeCommand(event)">
<div>
<label class="block text-sm font-medium text-gray-700">Command:</label>
<input id="commandInput" type="text" name="command" class="mt-1 block w-full border-gray-300 rounded-md shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" />
</div>
<button type="submit" class="mt-4 px-4 py-2 bg-green-600 text-white font-semibold rounded-lg shadow-md hover:bg-green-700">Execute Command</button>
<p id="commandOutput" class="mt-2 text-gray-700"></p>
</form>
<h2 class="text-xl font-bold mt-8">CPU Information</h2>
<pre id="cpuInfo" class="mt-4 bg-gray-200 p-4 rounded-md"></pre>
</div>
</body>
</html>