Spaces:
Sleeping
Sleeping
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>CPU Resource Manager</title> | |
<script src="https://cdn.tailwindcss.com"></script> | |
<style> | |
body { | |
background-color: #f7fafc; | |
} | |
.container { | |
max-width: 600px; | |
} | |
.button { | |
display: inline-block; | |
margin: 5px; | |
padding: 10px 20px; | |
font-size: 16px; | |
font-weight: bold; | |
text-align: center; | |
text-decoration: none; | |
border-radius: 5px; | |
color: white; | |
} | |
.button-primary { | |
background-color: #3b82f6; | |
} | |
.button-primary:hover { | |
background-color: #2563eb; | |
} | |
.button-secondary { | |
background-color: #10b981; | |
} | |
.button-secondary:hover { | |
background-color: #059669; | |
} | |
</style> | |
</head> | |
<body class="flex items-center justify-center min-h-screen"> | |
<div class="container bg-white shadow-md rounded-lg p-8"> | |
<h1 class="text-3xl font-bold mb-6 text-center">CPU Resource Manager</h1> | |
<div class="mb-6"> | |
<label for="file" class="block text-lg font-medium text-gray-700">Upload Files:</label> | |
<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"> | |
</div> | |
<div class="mb-6"> | |
<label for="script_content" class="block text-lg font-medium text-gray-700">Python Script Content:</label> | |
<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> | |
</div> | |
<div class="mb-6 flex justify-center"> | |
<button id="run_button" class="button button-primary">Run Script</button> | |
<button id="reload_button" class="button button-secondary">Reload CPU Info</button> | |
</div> | |
<div class="mb-6"> | |
<h2 class="text-2xl font-bold">Log Output:</h2> | |
<pre id="log_output" class="bg-gray-100 p-4 border border-gray-300 rounded-md shadow-sm overflow-auto"></pre> | |
</div> | |
<div class="mb-6"> | |
<h2 class="text-2xl font-bold">Connected CPUs Info:</h2> | |
<pre id="cpu_info" class="bg-gray-100 p-4 border border-gray-300 rounded-md shadow-sm overflow-auto"></pre> | |
</div> | |
</div> | |
<script> | |
document.getElementById('run_button').addEventListener('click', async function () { | |
const script_content = document.getElementById('script_content').value; | |
const files = document.getElementById('file').files; | |
const formData = new FormData(); | |
formData.append('script_content', script_content); | |
for (const file of files) { | |
formData.append('file', file); | |
} | |
const response = await fetch('/upload', { | |
method: 'POST', | |
body: formData, | |
}); | |
const result = await response.json(); | |
document.getElementById('log_output').textContent = result.log_output; | |
if (result.status === 'success' && result.download_url) { | |
const downloadLink = document.createElement('a'); | |
downloadLink.href = result.download_url; | |
downloadLink.textContent = 'Download Output Folder'; | |
downloadLink.classList.add('text-blue-500', 'hover:underline'); | |
document.getElementById('log_output').appendChild(document.createElement('br')); | |
document.getElementById('log_output').appendChild(downloadLink); | |
} | |
}); | |
document.getElementById('reload_button').addEventListener('click', async function () { | |
const response = await fetch('/cpu_info'); | |
const result = await response.json(); | |
document.getElementById('cpu_info').textContent = result.cpu_info; | |
}); | |
// Refresh CPU info every 2 seconds | |
setInterval(async function () { | |
const response = await fetch('/cpu_info'); | |
const result = await response.json(); | |
document.getElementById('cpu_info').textContent = result.cpu_info; | |
}, 2000); | |
// Initial load of CPU info | |
document.getElementById('reload_button').click(); | |
</script> | |
</body> | |
</html> | |