oscarwang2 commited on
Commit
133d361
1 Parent(s): 51289e5

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +111 -91
templates/index.html CHANGED
@@ -3,107 +3,127 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Dashboard</title>
7
- <link href="https://cdn.jsdelivr.net/npm/[email protected]/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
- document.getElementById('uploadLog').innerText = result.log_output || '';
19
- if (result.download_url) {
20
- document.getElementById('downloadLink').href = result.download_url;
21
- document.getElementById('downloadLink').style.display = 'inline';
 
22
  }
23
- }
24
 
25
- async function executeCommand(event) {
26
- event.preventDefault();
27
- let formData = new FormData();
28
- formData.append('command', document.getElementById('commandInput').value);
29
- let response = await fetch('/execute_command', {
30
  method: 'POST',
31
  body: formData
 
 
 
 
 
 
 
 
 
 
 
 
32
  });
33
- let result = await response.json();
34
- document.getElementById('commandOutput').innerText = result.log_output || '';
35
- }
36
 
37
- async function refreshCpuInfo() {
38
- let response = await fetch('/cpu_info');
39
- let result = await response.json();
40
- document.getElementById('cpuInfo').innerText = result.cpu_info || '';
 
 
41
  }
42
-
43
- setInterval(refreshCpuInfo, 2000);
44
  </script>
45
- </head>
46
- <body class="bg-gray-100">
47
- <div class="min-h-screen flex flex-col">
48
- <!-- Header -->
49
- <header class="bg-indigo-600 text-white py-4">
50
- <div class="container mx-auto flex justify-between items-center px-4">
51
- <h1 class="text-2xl font-bold">Dashboard</h1>
52
- <nav>
53
- <a href="#uploadSection" class="text-white hover:text-gray-300 px-4">Upload & Run</a>
54
- <a href="#commandSection" class="text-white hover:text-gray-300 px-4">Commands</a>
55
- <a href="#cpuInfoSection" class="text-white hover:text-gray-300 px-4">CPU Info</a>
56
- </nav>
57
- </div>
58
- </header>
59
-
60
- <!-- Main Content -->
61
- <main class="flex-grow container mx-auto px-4 py-6">
62
- <!-- Upload & Run Section -->
63
- <section id="uploadSection" class="bg-white shadow-md rounded-lg p-6 mb-6">
64
- <h2 class="text-xl font-semibold mb-4">Upload Files and Run Python Code</h2>
65
- <form id="uploadForm" class="space-y-4" onsubmit="handleUpload(event)">
66
- <div>
67
- <label class="block text-sm font-medium text-gray-700">Upload Files:</label>
68
- <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" />
69
- </div>
70
- <div>
71
- <label class="block text-sm font-medium text-gray-700">Python Script:</label>
72
- <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>
73
- </div>
74
- <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>
75
- <p id="uploadStatus" class="mt-2 text-red-600"></p>
76
- <pre id="uploadLog" class="mt-4 bg-gray-200 p-4 rounded-md"></pre>
77
- <a id="downloadLink" href="#" class="mt-4 text-indigo-600" style="display:none">Download Output</a>
78
- </form>
79
- </section>
80
-
81
- <!-- Command Execution Section -->
82
- <section id="commandSection" class="bg-white shadow-md rounded-lg p-6 mb-6">
83
- <h2 class="text-xl font-semibold mb-4">Execute Commands</h2>
84
- <form id="commandForm" class="space-y-4" onsubmit="executeCommand(event)">
85
- <div>
86
- <label class="block text-sm font-medium text-gray-700">Command:</label>
87
- <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" />
88
- </div>
89
- <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>
90
- <pre id="commandOutput" class="mt-4 bg-gray-200 p-4 rounded-md"></pre>
91
- </form>
92
- </section>
93
-
94
- <!-- CPU Information Section -->
95
- <section id="cpuInfoSection" class="bg-white shadow-md rounded-lg p-6">
96
- <h2 class="text-xl font-semibold mb-4">CPU Information</h2>
97
- <pre id="cpuInfo" class="bg-gray-200 p-4 rounded-md"></pre>
98
- </section>
99
- </main>
100
-
101
- <!-- Footer -->
102
- <footer class="bg-gray-800 text-white py-4">
103
- <div class="container mx-auto text-center">
104
- <p>&copy; 2024 Your Dashboard</p>
105
- </div>
106
- </footer>
107
- </div>
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>MPI Distributed Computing Interface</title>
7
+ <style>
8
+ body {
9
+ font-family: Arial, sans-serif;
10
+ margin: 20px;
11
+ }
12
+ .container {
13
+ margin-bottom: 20px;
14
+ }
15
+ #logs {
16
+ border: 1px solid #ccc;
17
+ padding: 10px;
18
+ height: 200px;
19
+ overflow-y: scroll;
20
+ background-color: #f9f9f9;
21
+ }
22
+ </style>
23
+ </head>
24
+ <body>
25
+ <h1>MPI Distributed Computing Interface</h1>
26
+
27
+ <div class="container">
28
+ <label for="folderUpload">Upload a Folder:</label>
29
+ <input type="file" id="folderUpload" webkitdirectory directory multiple>
30
+ </div>
31
+
32
+ <div class="container">
33
+ <label for="pythonFileUpload">Upload a Python File:</label>
34
+ <input type="file" id="pythonFileUpload" accept=".py">
35
+ </div>
36
+
37
+ <div class="container">
38
+ <label for="scriptContent">Script Content:</label>
39
+ <textarea id="scriptContent" rows="10" cols="50" placeholder="Paste your Python script content here..."></textarea>
40
+ </div>
41
+
42
+ <div class="container">
43
+ <button id="startMPI">Start MPI Distributed Computing</button>
44
+ </div>
45
+
46
+ <div class="container">
47
+ <label for="commandInput">Run Command:</label>
48
+ <input type="text" id="commandInput" placeholder="Enter command (e.g., pip install ...)">
49
+ <button id="runCommand">Run</button>
50
+ </div>
51
+
52
+ <div class="container">
53
+ <h2>Logs</h2>
54
+ <div id="logs"></div>
55
+ </div>
56
+
57
  <script>
58
+ document.getElementById('startMPI').addEventListener('click', function() {
59
+ const folderInput = document.getElementById('folderUpload');
60
+ const scriptContent = document.getElementById('scriptContent').value;
61
+ const formData = new FormData();
62
+
63
+ if (folderInput.files.length === 0 || !scriptContent) {
64
+ logMessage('Please upload a folder and provide script content.');
65
+ return;
66
+ }
67
+
68
+ for (let i = 0; i < folderInput.files.length; i++) {
69
+ formData.append('file', folderInput.files[i]);
70
+ }
71
+ formData.append('script_content', scriptContent);
72
+
73
+ fetch('/upload', {
74
  method: 'POST',
75
  body: formData
76
+ })
77
+ .then(response => response.json())
78
+ .then(data => {
79
+ if (data.status === 'success') {
80
+ logMessage('MPI distributed computing started successfully.');
81
+ logMessage('Log Output: ' + data.log_output);
82
+ logMessage('Download Output: <a href="' + data.download_url + '">Download</a>');
83
+ } else {
84
+ logMessage('Error: ' + data.message);
85
+ }
86
+ })
87
+ .catch(error => {
88
+ logMessage('Error: ' + error.message);
89
  });
90
+ });
91
+
92
+ document.getElementById('runCommand').addEventListener('click', function() {
93
+ const command = document.getElementById('commandInput').value;
94
+ if (!command) {
95
+ logMessage('Please enter a command.');
96
+ return;
97
  }
 
98
 
99
+ const formData = new FormData();
100
+ formData.append('command', command);
101
+
102
+ fetch('/execute_command', {
 
103
  method: 'POST',
104
  body: formData
105
+ })
106
+ .then(response => response.json())
107
+ .then(data => {
108
+ if (data.status === 'success') {
109
+ logMessage('Command executed successfully.');
110
+ logMessage('Log Output: ' + data.log_output);
111
+ } else {
112
+ logMessage('Error: ' + data.message);
113
+ }
114
+ })
115
+ .catch(error => {
116
+ logMessage('Error: ' + error.message);
117
  });
118
+ });
 
 
119
 
120
+ function logMessage(message) {
121
+ const logs = document.getElementById('logs');
122
+ const logEntry = document.createElement('div');
123
+ logEntry.innerHTML = message;
124
+ logs.appendChild(logEntry);
125
+ logs.scrollTop = logs.scrollHeight;
126
  }
 
 
127
  </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  </body>
129
+ </html>