Spaces:
Running
Running
Commit
·
1e8d830
1
Parent(s):
6b9468a
autoclicking on various buttons for the starting and the launching. Added royal override. Added -ll 5 option to yarn start
Browse files- hf_server.js +60 -49
- omnitool_init.sh +1 -1
hf_server.js
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* All rights reserved.
|
4 |
*/
|
5 |
//@ts-check
|
6 |
-
const VERSION = '0.6.0.hf.015.
|
7 |
|
8 |
const express = require('express');
|
9 |
const http = require('http');
|
@@ -33,6 +33,7 @@ const targetDir = '/data';//'omnitool/data';
|
|
33 |
|
34 |
const DELAY_OMNITOOL_SET_TO_RUNNING = 2000; // 2 seconds
|
35 |
const CHECK_OMNI_INTERVAL = 60000; // 1 minute
|
|
|
36 |
|
37 |
// Global variable
|
38 |
global.OMNITOOL_RUNNING = false;
|
@@ -105,6 +106,12 @@ const COMMON_STYLES =
|
|
105 |
`<script>
|
106 |
// Script to check Hugging Face login status and control 'Clone Repo' button
|
107 |
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
function startServer() {
|
109 |
document.getElementById('startServerButton').classList.remove
|
110 |
('highlight-button-green');
|
@@ -139,42 +146,42 @@ const COMMON_STYLES =
|
|
139 |
const interval = setInterval(() => {
|
140 |
fetch('/omnitool-logs')
|
141 |
.then(response => response.json())
|
142 |
-
.then(data =>
|
|
|
143 |
const logContainer = document.getElementById('logContainer');
|
144 |
logContainer.innerText = data.logs.join("");
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
document.getElementById('refreshButton').disabled
|
149 |
-
|
150 |
-
|
151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
}
|
153 |
-
else
|
154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
}
|
156 |
});
|
157 |
-
},
|
158 |
-
|
159 |
-
const interval2 = setInterval(() => {
|
160 |
-
fetch('/omnitool-logs')
|
161 |
-
.then(response => response.json())
|
162 |
-
.then(data => {
|
163 |
-
const logContainer = document.getElementById('logContainer');
|
164 |
-
logContainer.innerText = data.logs.join("");
|
165 |
-
if (data.ready) {
|
166 |
-
|
167 |
-
scrollToBottom(logContainer);
|
168 |
-
document.getElementById('refreshButton').disabled = false;
|
169 |
-
document.getElementById('refreshButton').classList.add('highlight-button');
|
170 |
-
clearInterval(interval);
|
171 |
|
172 |
-
}
|
173 |
-
else {
|
174 |
-
scrollToBottom(logContainer);
|
175 |
-
}
|
176 |
-
});
|
177 |
-
}, 500);
|
178 |
}
|
179 |
|
180 |
function scrollToBottom(element) {
|
@@ -212,9 +219,12 @@ async function startOmnitoolServer()
|
|
212 |
const omnitoolStartProcess = spawn(OMNITOOL_INSTALL_SCRIPT);
|
213 |
omnitoolStartProcess.stdout.on('data', (data) =>
|
214 |
{
|
|
|
|
|
|
|
215 |
global.logs.push(data.toString());
|
216 |
-
console.log(`omnitool
|
217 |
-
|
218 |
if (!global.OMNITOOL_RUNNING)
|
219 |
{
|
220 |
if (data.toString().includes(`Server has started and is ready to accept connections`))
|
@@ -223,12 +233,11 @@ async function startOmnitoolServer()
|
|
223 |
setOmnitoolRunning(true);
|
224 |
}
|
225 |
}
|
226 |
-
|
227 |
});
|
228 |
|
229 |
omnitoolStartProcess.stderr.on('data', (data) =>
|
230 |
{
|
231 |
-
console.error(`omnitool stderr
|
232 |
global.logs.push(data.toString());
|
233 |
});
|
234 |
|
@@ -281,7 +290,6 @@ function setOmnitoolRunning(set_running)
|
|
281 |
// Function to check the status of the external service
|
282 |
async function checkOmnitoolStatus()
|
283 |
{
|
284 |
-
console.log("Checking external service");
|
285 |
try
|
286 |
{
|
287 |
//@ts-ignore
|
@@ -296,7 +304,6 @@ async function checkOmnitoolStatus()
|
|
296 |
}
|
297 |
} catch (error)
|
298 |
{
|
299 |
-
console.log('Please press [START] button');
|
300 |
setOmnitoolRunning(false);
|
301 |
}
|
302 |
}
|
@@ -375,7 +382,7 @@ async function handleGetRoot(req, res)
|
|
375 |
await checkOmnitoolStatus();
|
376 |
}
|
377 |
|
378 |
-
if (global.CONNECTED_TO_MASTER)
|
379 |
{
|
380 |
let page_message ="";
|
381 |
|
@@ -407,13 +414,11 @@ async function handleGetRoot(req, res)
|
|
407 |
</body>
|
408 |
</html>`;
|
409 |
|
410 |
-
console.log(`page_html = ${page_html}`);
|
411 |
-
|
412 |
res.writeHead(200, { 'Content-Type': 'text/html' });
|
413 |
res.end(page_html);
|
414 |
return;
|
415 |
}
|
416 |
-
|
417 |
|
418 |
if (!req.session.isVisited)
|
419 |
{
|
@@ -421,6 +426,7 @@ async function handleGetRoot(req, res)
|
|
421 |
page_message += `<div style="color: green;">You are now connected to the space [ ${global.LOCAL_URL} ]</div>`
|
422 |
page_message += `<div style="color: red;">If this is NOT your SPACE, it is HIGHLY recommended that you duplicate this space and make it private to secure your keys, recipes and outputs.</div>`
|
423 |
page_message += `<div>DUPLICATING and using your own SPACE is FREE. You can do it by pressing this button: <a href="${HF_SPACE_DUPLICATE_URL}" target="_blank" class="button-like-link" id="duplicateRepoButton">DUPLICATE SPACE</a></div><div>However, consider choosing the 20 Gig Storage option (~ 5 USD/month) to persist keys, recipes and outputs between server restarts.</div>`;
|
|
|
424 |
page_message += `<div>To ACCESS OMNITOOL on this SPACE: press the [START] button below.</div>`;
|
425 |
|
426 |
const gotoButtonClass = 'highlight-button';
|
@@ -439,11 +445,12 @@ async function handleGetRoot(req, res)
|
|
439 |
${page_message}
|
440 |
<p></p>
|
441 |
${buttons_html}
|
|
|
|
|
442 |
${SCRIPTS}
|
443 |
</body>
|
444 |
</html>
|
445 |
`;
|
446 |
-
console.log(`page_html = ${page_html}`);
|
447 |
res.writeHead(200, { 'Content-Type': 'text/html' });
|
448 |
res.end(page_html);
|
449 |
return;
|
@@ -451,15 +458,15 @@ async function handleGetRoot(req, res)
|
|
451 |
|
452 |
if (!global.OMNITOOL_RUNNING)
|
453 |
{
|
454 |
-
let page_message ="";
|
455 |
-
page_message += `<div>It looks like Omnitool is not running on this Space. Let's fix that.</div><div>Press the [LAUNCH] button below.</div><div>Once Omnitool is running, you will be able to access it by pressing the [REFRESH] button.</div>`;
|
456 |
|
|
|
|
|
457 |
console.log('Omnitool server is not running');
|
458 |
const startButtonClass = 'highlight-button-green';
|
459 |
|
460 |
let buttonsHTML = `
|
461 |
-
<button id="startServerButton" class="${startButtonClass}" onclick="startServer()">
|
462 |
-
<button id="refreshButton" class="${''}" disabled onclick="refreshPage()">
|
463 |
`;
|
464 |
|
465 |
const SCRIPTS = getScriptsHtml();
|
@@ -480,9 +487,13 @@ async function handleGetRoot(req, res)
|
|
480 |
</html>
|
481 |
`;
|
482 |
|
483 |
-
console.log(`page_html = ${page_html}`);
|
484 |
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
|
|
|
|
|
485 |
res.end(page_html);
|
|
|
|
|
486 |
return;
|
487 |
}
|
488 |
|
@@ -513,7 +524,7 @@ function setGlobals(req)
|
|
513 |
|
514 |
}
|
515 |
|
516 |
-
async function
|
517 |
{
|
518 |
// Start server
|
519 |
http.createServer(app).listen(PROXY_PORT_OMNITOOL, () =>
|
@@ -557,7 +568,7 @@ async function main(app)
|
|
557 |
}));
|
558 |
try
|
559 |
{
|
560 |
-
await
|
561 |
}
|
562 |
catch (error)
|
563 |
{
|
|
|
3 |
* All rights reserved.
|
4 |
*/
|
5 |
//@ts-check
|
6 |
+
const VERSION = '0.6.0.hf.015.e';
|
7 |
|
8 |
const express = require('express');
|
9 |
const http = require('http');
|
|
|
33 |
|
34 |
const DELAY_OMNITOOL_SET_TO_RUNNING = 2000; // 2 seconds
|
35 |
const CHECK_OMNI_INTERVAL = 60000; // 1 minute
|
36 |
+
const MAX_LOG_SIZE = 1000; // Set your desired maximum log size
|
37 |
|
38 |
// Global variable
|
39 |
global.OMNITOOL_RUNNING = false;
|
|
|
106 |
`<script>
|
107 |
// Script to check Hugging Face login status and control 'Clone Repo' button
|
108 |
|
109 |
+
if (document.getElementById('startServerButton'))
|
110 |
+
{
|
111 |
+
// Call startServer after 1 second
|
112 |
+
setTimeout(startServer, 1000);
|
113 |
+
}
|
114 |
+
|
115 |
function startServer() {
|
116 |
document.getElementById('startServerButton').classList.remove
|
117 |
('highlight-button-green');
|
|
|
146 |
const interval = setInterval(() => {
|
147 |
fetch('/omnitool-logs')
|
148 |
.then(response => response.json())
|
149 |
+
.then(data =>
|
150 |
+
{
|
151 |
const logContainer = document.getElementById('logContainer');
|
152 |
logContainer.innerText = data.logs.join("");
|
153 |
+
|
154 |
+
if (data.ready)
|
155 |
+
{
|
156 |
+
if (document.getElementById('refreshButton').disabled == true)
|
157 |
+
{
|
158 |
+
document.getElementById('refreshButton').disabled = false;
|
159 |
+
|
160 |
+
scrollToBottom(logContainer);
|
161 |
+
document.getElementById('refreshButton').classList.add('highlight-button');
|
162 |
+
setTimeout(() => {
|
163 |
+
window.location.reload(); // Refresh the page after 2 seconds
|
164 |
+
}, 3000);
|
165 |
+
}
|
166 |
}
|
167 |
+
else
|
168 |
+
{
|
169 |
+
if (document.getElementById('refreshButton').disabled == false)
|
170 |
+
{
|
171 |
+
document.getElementById('refreshButton').disabled = true;
|
172 |
+
document.getElementById('refreshButton').classList.remove('highlight-button');
|
173 |
+
setTimeout(() => {
|
174 |
+
window.location.reload(); // Refresh the page after 2 seconds
|
175 |
+
}, 3000);
|
176 |
+
}
|
177 |
+
else
|
178 |
+
{
|
179 |
+
scrollToBottom(logContainer);
|
180 |
+
}
|
181 |
}
|
182 |
});
|
183 |
+
}, 2000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
}
|
186 |
|
187 |
function scrollToBottom(element) {
|
|
|
219 |
const omnitoolStartProcess = spawn(OMNITOOL_INSTALL_SCRIPT);
|
220 |
omnitoolStartProcess.stdout.on('data', (data) =>
|
221 |
{
|
222 |
+
if (global.logs.length >= MAX_LOG_SIZE) {
|
223 |
+
global.logs.shift(); // Remove the oldest log entry
|
224 |
+
}
|
225 |
global.logs.push(data.toString());
|
226 |
+
console.log(`[omnitool] ${data}`);
|
227 |
+
|
228 |
if (!global.OMNITOOL_RUNNING)
|
229 |
{
|
230 |
if (data.toString().includes(`Server has started and is ready to accept connections`))
|
|
|
233 |
setOmnitoolRunning(true);
|
234 |
}
|
235 |
}
|
|
|
236 |
});
|
237 |
|
238 |
omnitoolStartProcess.stderr.on('data', (data) =>
|
239 |
{
|
240 |
+
console.error(`[omnitool stderr] ${data}`);
|
241 |
global.logs.push(data.toString());
|
242 |
});
|
243 |
|
|
|
290 |
// Function to check the status of the external service
|
291 |
async function checkOmnitoolStatus()
|
292 |
{
|
|
|
293 |
try
|
294 |
{
|
295 |
//@ts-ignore
|
|
|
304 |
}
|
305 |
} catch (error)
|
306 |
{
|
|
|
307 |
setOmnitoolRunning(false);
|
308 |
}
|
309 |
}
|
|
|
382 |
await checkOmnitoolStatus();
|
383 |
}
|
384 |
|
385 |
+
if (global.CONNECTED_TO_MASTER && !req.session.roayl_override)
|
386 |
{
|
387 |
let page_message ="";
|
388 |
|
|
|
414 |
</body>
|
415 |
</html>`;
|
416 |
|
|
|
|
|
417 |
res.writeHead(200, { 'Content-Type': 'text/html' });
|
418 |
res.end(page_html);
|
419 |
return;
|
420 |
}
|
421 |
+
|
422 |
|
423 |
if (!req.session.isVisited)
|
424 |
{
|
|
|
426 |
page_message += `<div style="color: green;">You are now connected to the space [ ${global.LOCAL_URL} ]</div>`
|
427 |
page_message += `<div style="color: red;">If this is NOT your SPACE, it is HIGHLY recommended that you duplicate this space and make it private to secure your keys, recipes and outputs.</div>`
|
428 |
page_message += `<div>DUPLICATING and using your own SPACE is FREE. You can do it by pressing this button: <a href="${HF_SPACE_DUPLICATE_URL}" target="_blank" class="button-like-link" id="duplicateRepoButton">DUPLICATE SPACE</a></div><div>However, consider choosing the 20 Gig Storage option (~ 5 USD/month) to persist keys, recipes and outputs between server restarts.</div>`;
|
429 |
+
page_message += `<p></p><p></p>`;
|
430 |
page_message += `<div>To ACCESS OMNITOOL on this SPACE: press the [START] button below.</div>`;
|
431 |
|
432 |
const gotoButtonClass = 'highlight-button';
|
|
|
445 |
${page_message}
|
446 |
<p></p>
|
447 |
${buttons_html}
|
448 |
+
<p></p>
|
449 |
+
${LOG_CONTAINER_HTML}
|
450 |
${SCRIPTS}
|
451 |
</body>
|
452 |
</html>
|
453 |
`;
|
|
|
454 |
res.writeHead(200, { 'Content-Type': 'text/html' });
|
455 |
res.end(page_html);
|
456 |
return;
|
|
|
458 |
|
459 |
if (!global.OMNITOOL_RUNNING)
|
460 |
{
|
|
|
|
|
461 |
|
462 |
+
let page_message ="";
|
463 |
+
page_message += `<div>It looks like Omnitool is not running on this Space. Let's fix that.</div>`;
|
464 |
console.log('Omnitool server is not running');
|
465 |
const startButtonClass = 'highlight-button-green';
|
466 |
|
467 |
let buttonsHTML = `
|
468 |
+
<button id="startServerButton" class="${startButtonClass}" onclick="startServer()">LAUNCHING...</button>
|
469 |
+
<button id="refreshButton" class="${''}" disabled onclick="refreshPage()">REFRESHING...</button>
|
470 |
`;
|
471 |
|
472 |
const SCRIPTS = getScriptsHtml();
|
|
|
487 |
</html>
|
488 |
`;
|
489 |
|
|
|
490 |
res.writeHead(200, { 'Content-Type': 'text/html' });
|
491 |
+
|
492 |
+
|
493 |
+
|
494 |
res.end(page_html);
|
495 |
+
|
496 |
+
|
497 |
return;
|
498 |
}
|
499 |
|
|
|
524 |
|
525 |
}
|
526 |
|
527 |
+
async function startHuggingfaceServer()
|
528 |
{
|
529 |
// Start server
|
530 |
http.createServer(app).listen(PROXY_PORT_OMNITOOL, () =>
|
|
|
568 |
}));
|
569 |
try
|
570 |
{
|
571 |
+
await startHuggingfaceServer();
|
572 |
}
|
573 |
catch (error)
|
574 |
{
|
omnitool_init.sh
CHANGED
@@ -44,4 +44,4 @@ else
|
|
44 |
fi
|
45 |
|
46 |
echo "[->] YARN START "
|
47 |
-
yarn start -u -rb -ll
|
|
|
44 |
fi
|
45 |
|
46 |
echo "[->] YARN START "
|
47 |
+
yarn start -u -rb -ll 5 -R blocks
|