File size: 4,629 Bytes
3b405b9
 
 
 
 
 
 
12c761b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3b405b9
12c761b
 
 
3b405b9
12c761b
3b405b9
 
 
12c761b
 
3b405b9
12c761b
 
 
3b405b9
 
 
12c761b
3b405b9
 
 
12c761b
3b405b9
 
 
 
 
12c761b
3b405b9
 
12c761b
3b405b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12c761b
 
 
 
 
 
 
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<!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>
    <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>