File size: 3,584 Bytes
3b405b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!DOCTYPE html>
<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>
</head>
<body class="bg-gray-100 p-8">
    <div class="container mx-auto">
        <h1 class="text-3xl font-bold mb-6">CPU Resource Manager</h1>
        <div class="mb-6">
            <label for="script_name" class="block text-lg font-medium text-gray-700">Python Script Name:</label>
            <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">
        </div>
        <div class="mb-6">
            <label for="file" class="block text-lg font-medium text-gray-700">Upload Folder:</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">
            <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>
        </div>
        <div class="mb-6">
            <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>
        </div>
        <div class="mb-6">
            <h2 class="text-2xl font-bold">Log Output:</h2>
            <pre id="log_output" class="bg-white 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-white 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_name = document.getElementById('script_name').value;
            const files = document.getElementById('file').files;
            const formData = new FormData();
            formData.append('script_name', script_name);
            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;
        });

        // Initial load of CPU info
        document.getElementById('reload_button').click();
    </script>
</body>
</html>