Spaces:
Sleeping
Sleeping
oscarwang2
commited on
Commit
•
3b405b9
1
Parent(s):
bc57054
Create templates/index.html
Browse files- templates/index.html +73 -0
templates/index.html
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>CPU Resource Manager</title>
|
7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
8 |
+
</head>
|
9 |
+
<body class="bg-gray-100 p-8">
|
10 |
+
<div class="container mx-auto">
|
11 |
+
<h1 class="text-3xl font-bold mb-6">CPU Resource Manager</h1>
|
12 |
+
<div class="mb-6">
|
13 |
+
<label for="script_name" class="block text-lg font-medium text-gray-700">Python Script Name:</label>
|
14 |
+
<input type="text" id="script_name" name="script_name" 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">
|
15 |
+
</div>
|
16 |
+
<div class="mb-6">
|
17 |
+
<label for="file" class="block text-lg font-medium text-gray-700">Upload Folder:</label>
|
18 |
+
<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">
|
19 |
+
</div>
|
20 |
+
<div class="mb-6">
|
21 |
+
<button id="run_button" class="px-4 py-2 bg-blue-500 text-white rounded-md shadow-sm hover:bg-blue-600">Run Script</button>
|
22 |
+
</div>
|
23 |
+
<div class="mb-6">
|
24 |
+
<button id="reload_button" class="px-4 py-2 bg-green-500 text-white rounded-md shadow-sm hover:bg-green-600">Reload CPU Info</button>
|
25 |
+
</div>
|
26 |
+
<div class="mb-6">
|
27 |
+
<h2 class="text-2xl font-bold">Log Output:</h2>
|
28 |
+
<pre id="log_output" class="bg-white p-4 border border-gray-300 rounded-md shadow-sm overflow-auto"></pre>
|
29 |
+
</div>
|
30 |
+
<div class="mb-6">
|
31 |
+
<h2 class="text-2xl font-bold">Connected CPUs Info:</h2>
|
32 |
+
<pre id="cpu_info" class="bg-white p-4 border border-gray-300 rounded-md shadow-sm overflow-auto"></pre>
|
33 |
+
</div>
|
34 |
+
</div>
|
35 |
+
|
36 |
+
<script>
|
37 |
+
document.getElementById('run_button').addEventListener('click', async function () {
|
38 |
+
const script_name = document.getElementById('script_name').value;
|
39 |
+
const files = document.getElementById('file').files;
|
40 |
+
const formData = new FormData();
|
41 |
+
formData.append('script_name', script_name);
|
42 |
+
for (const file of files) {
|
43 |
+
formData.append('file', file);
|
44 |
+
}
|
45 |
+
|
46 |
+
const response = await fetch('/upload', {
|
47 |
+
method: 'POST',
|
48 |
+
body: formData,
|
49 |
+
});
|
50 |
+
const result = await response.json();
|
51 |
+
document.getElementById('log_output').textContent = result.log_output;
|
52 |
+
|
53 |
+
if (result.status === 'success' && result.download_url) {
|
54 |
+
const downloadLink = document.createElement('a');
|
55 |
+
downloadLink.href = result.download_url;
|
56 |
+
downloadLink.textContent = 'Download Output Folder';
|
57 |
+
downloadLink.classList.add('text-blue-500', 'hover:underline');
|
58 |
+
document.getElementById('log_output').appendChild(document.createElement('br'));
|
59 |
+
document.getElementById('log_output').appendChild(downloadLink);
|
60 |
+
}
|
61 |
+
});
|
62 |
+
|
63 |
+
document.getElementById('reload_button').addEventListener('click', async function () {
|
64 |
+
const response = await fetch('/cpu_info');
|
65 |
+
const result = await response.json();
|
66 |
+
document.getElementById('cpu_info').textContent = result.cpu_info;
|
67 |
+
});
|
68 |
+
|
69 |
+
// Initial load of CPU info
|
70 |
+
document.getElementById('reload_button').click();
|
71 |
+
</script>
|
72 |
+
</body>
|
73 |
+
</html>
|