Spaces:
Sleeping
Sleeping
Oscar Wang
commited on
Update templates/index.html
Browse files- templates/index.html +59 -94
templates/index.html
CHANGED
|
@@ -3,107 +3,72 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>
|
| 7 |
-
<
|
| 8 |
-
<style>
|
| 9 |
-
body {
|
| 10 |
-
background-color: #f7fafc;
|
| 11 |
-
}
|
| 12 |
-
.container {
|
| 13 |
-
max-width: 600px;
|
| 14 |
-
}
|
| 15 |
-
.button {
|
| 16 |
-
display: inline-block;
|
| 17 |
-
margin: 5px;
|
| 18 |
-
padding: 10px 20px;
|
| 19 |
-
font-size: 16px;
|
| 20 |
-
font-weight: bold;
|
| 21 |
-
text-align: center;
|
| 22 |
-
text-decoration: none;
|
| 23 |
-
border-radius: 5px;
|
| 24 |
-
color: white;
|
| 25 |
-
}
|
| 26 |
-
.button-primary {
|
| 27 |
-
background-color: #3b82f6;
|
| 28 |
-
}
|
| 29 |
-
.button-primary:hover {
|
| 30 |
-
background-color: #2563eb;
|
| 31 |
-
}
|
| 32 |
-
.button-secondary {
|
| 33 |
-
background-color: #10b981;
|
| 34 |
-
}
|
| 35 |
-
.button-secondary:hover {
|
| 36 |
-
background-color: #059669;
|
| 37 |
-
}
|
| 38 |
-
</style>
|
| 39 |
-
</head>
|
| 40 |
-
<body class="flex items-center justify-center min-h-screen">
|
| 41 |
-
<div class="container bg-white shadow-md rounded-lg p-8">
|
| 42 |
-
<h1 class="text-3xl font-bold mb-6 text-center">CPU Resource Manager</h1>
|
| 43 |
-
<div class="mb-6">
|
| 44 |
-
<label for="file" class="block text-lg font-medium text-gray-700">Upload Files:</label>
|
| 45 |
-
<input type="file" id="file" name="file" multiple class="mt-1 p-2 block w-full border border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
|
| 46 |
-
</div>
|
| 47 |
-
<div class="mb-6">
|
| 48 |
-
<label for="script_content" class="block text-lg font-medium text-gray-700">Python Script Content:</label>
|
| 49 |
-
<textarea id="script_content" name="script_content" rows="10" class="mt-1 p-2 block w-full border border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"></textarea>
|
| 50 |
-
</div>
|
| 51 |
-
<div class="mb-6 flex justify-center">
|
| 52 |
-
<button id="run_button" class="button button-primary">Run Script</button>
|
| 53 |
-
<button id="reload_button" class="button button-secondary">Reload CPU Info</button>
|
| 54 |
-
</div>
|
| 55 |
-
<div class="mb-6">
|
| 56 |
-
<h2 class="text-2xl font-bold">Log Output:</h2>
|
| 57 |
-
<pre id="log_output" class="bg-gray-100 p-4 border border-gray-300 rounded-md shadow-sm overflow-auto"></pre>
|
| 58 |
-
</div>
|
| 59 |
-
<div class="mb-6">
|
| 60 |
-
<h2 class="text-2xl font-bold">Connected CPUs Info:</h2>
|
| 61 |
-
<pre id="cpu_info" class="bg-gray-100 p-4 border border-gray-300 rounded-md shadow-sm overflow-auto"></pre>
|
| 62 |
-
</div>
|
| 63 |
-
</div>
|
| 64 |
-
|
| 65 |
<script>
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
formData.append('script_content', script_content);
|
| 71 |
-
for (const file of files) {
|
| 72 |
-
formData.append('file', file);
|
| 73 |
-
}
|
| 74 |
-
|
| 75 |
-
const response = await fetch('/upload', {
|
| 76 |
method: 'POST',
|
| 77 |
-
body: formData
|
| 78 |
});
|
| 79 |
-
|
| 80 |
-
document.getElementById('
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
downloadLink.href = result.download_url;
|
| 85 |
-
downloadLink.textContent = 'Download Output Folder';
|
| 86 |
-
downloadLink.classList.add('text-blue-500', 'hover:underline');
|
| 87 |
-
document.getElementById('log_output').appendChild(document.createElement('br'));
|
| 88 |
-
document.getElementById('log_output').appendChild(downloadLink);
|
| 89 |
}
|
| 90 |
-
}
|
| 91 |
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
document.getElementById('
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
}, 2000);
|
| 104 |
|
| 105 |
-
|
| 106 |
-
document.getElementById('reload_button').click();
|
| 107 |
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
</body>
|
| 109 |
</html>
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>File Upload and Command Execution</title>
|
| 7 |
+
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
<script>
|
| 9 |
+
async function handleUpload(event) {
|
| 10 |
+
event.preventDefault();
|
| 11 |
+
let formData = new FormData(document.getElementById('uploadForm'));
|
| 12 |
+
let response = await fetch('/upload', {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
method: 'POST',
|
| 14 |
+
body: formData
|
| 15 |
});
|
| 16 |
+
let result = await response.json();
|
| 17 |
+
document.getElementById('uploadStatus').innerText = result.message || '';
|
| 18 |
+
if (result.download_url) {
|
| 19 |
+
document.getElementById('downloadLink').href = result.download_url;
|
| 20 |
+
document.getElementById('downloadLink').style.display = 'inline';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
}
|
| 22 |
+
}
|
| 23 |
|
| 24 |
+
async function executeCommand(event) {
|
| 25 |
+
event.preventDefault();
|
| 26 |
+
let formData = new FormData();
|
| 27 |
+
formData.append('command', document.getElementById('commandInput').value);
|
| 28 |
+
let response = await fetch('/execute_command', {
|
| 29 |
+
method: 'POST',
|
| 30 |
+
body: formData
|
| 31 |
+
});
|
| 32 |
+
let result = await response.json();
|
| 33 |
+
document.getElementById('commandOutput').innerText = result.log_output || '';
|
| 34 |
+
}
|
| 35 |
|
| 36 |
+
async function refreshCpuInfo() {
|
| 37 |
+
let response = await fetch('/cpu_info');
|
| 38 |
+
let result = await response.json();
|
| 39 |
+
document.getElementById('cpuInfo').innerText = result.cpu_info || '';
|
| 40 |
+
}
|
|
|
|
| 41 |
|
| 42 |
+
setInterval(refreshCpuInfo, 2000);
|
|
|
|
| 43 |
</script>
|
| 44 |
+
</head>
|
| 45 |
+
<body class="bg-gray-100 flex flex-col items-center justify-center min-h-screen py-6">
|
| 46 |
+
<div class="w-full max-w-4xl bg-white p-6 rounded-lg shadow-lg">
|
| 47 |
+
<h1 class="text-2xl font-bold mb-4">Upload Files and Run Python Code</h1>
|
| 48 |
+
<form id="uploadForm" class="space-y-4" onsubmit="handleUpload(event)">
|
| 49 |
+
<div>
|
| 50 |
+
<label class="block text-sm font-medium text-gray-700">Upload Files:</label>
|
| 51 |
+
<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" />
|
| 52 |
+
</div>
|
| 53 |
+
<div>
|
| 54 |
+
<label class="block text-sm font-medium text-gray-700">Python Script:</label>
|
| 55 |
+
<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>
|
| 56 |
+
</div>
|
| 57 |
+
<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>
|
| 58 |
+
<p id="uploadStatus" class="mt-2 text-red-600"></p>
|
| 59 |
+
<a id="downloadLink" href="#" class="mt-4 text-indigo-600" style="display:none">Download Output</a>
|
| 60 |
+
</form>
|
| 61 |
+
<h2 class="text-xl font-bold mt-8">Execute Commands</h2>
|
| 62 |
+
<form id="commandForm" class="space-y-4 mt-4" onsubmit="executeCommand(event)">
|
| 63 |
+
<div>
|
| 64 |
+
<label class="block text-sm font-medium text-gray-700">Command:</label>
|
| 65 |
+
<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" />
|
| 66 |
+
</div>
|
| 67 |
+
<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>
|
| 68 |
+
<p id="commandOutput" class="mt-2 text-gray-700"></p>
|
| 69 |
+
</form>
|
| 70 |
+
<h2 class="text-xl font-bold mt-8">CPU Information</h2>
|
| 71 |
+
<pre id="cpuInfo" class="mt-4 bg-gray-200 p-4 rounded-md"></pre>
|
| 72 |
+
</div>
|
| 73 |
</body>
|
| 74 |
</html>
|