Spaces:
Sleeping
Sleeping
fix
Browse files
main.py
CHANGED
|
@@ -517,9 +517,9 @@ def main():
|
|
| 517 |
margin-bottom: 16px !important;
|
| 518 |
}
|
| 519 |
"""
|
| 520 |
-
|
| 521 |
-
(
|
| 522 |
-
|
| 523 |
"Crunching your documents...",
|
| 524 |
"Warming up the AI...",
|
| 525 |
"Extracting knowledge...",
|
|
@@ -532,65 +532,64 @@ def main():
|
|
| 532 |
"Almost ready..."
|
| 533 |
];
|
| 534 |
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
|
| 540 |
-
|
| 541 |
-
|
| 542 |
|
| 543 |
-
|
| 544 |
if (uploadMessages.length === 0) return "";
|
| 545 |
if (uploadMessages.length === 1) return uploadMessages[0];
|
| 546 |
-
|
| 547 |
do { m = uploadMessages[Math.floor(Math.random() * uploadMessages.length)]; }
|
| 548 |
while (m === lastMsg);
|
| 549 |
lastMsg = m;
|
| 550 |
return m;
|
| 551 |
-
}
|
| 552 |
|
| 553 |
-
|
| 554 |
-
|
| 555 |
|
| 556 |
-
|
| 557 |
-
|
| 558 |
|
| 559 |
-
|
| 560 |
if (msgInterval || timerInterval) return;
|
| 561 |
startMs = Date.now();
|
| 562 |
setMsg(pickMsg());
|
| 563 |
|
| 564 |
-
msgInterval = setInterval(
|
| 565 |
|
| 566 |
-
|
| 567 |
if (t) {
|
| 568 |
t.textContent = fmtElapsed();
|
| 569 |
-
timerInterval = setInterval(
|
| 570 |
}
|
| 571 |
-
}
|
| 572 |
|
| 573 |
-
|
| 574 |
if (msgInterval) { clearInterval(msgInterval); msgInterval = null; }
|
| 575 |
if (timerInterval) { clearInterval(timerInterval); timerInterval = null; }
|
| 576 |
-
|
| 577 |
if (t) t.textContent = "";
|
| 578 |
-
}
|
| 579 |
|
| 580 |
-
|
| 581 |
-
|
| 582 |
if (isVisible(r)) start();
|
| 583 |
else stop();
|
| 584 |
-
}
|
| 585 |
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
obs.observe(document.body, { subtree: true, childList: true, attributes: true });
|
| 589 |
-
} catch (e) {}
|
| 590 |
|
| 591 |
window.addEventListener("load", tick);
|
| 592 |
-
setInterval(tick, 500);
|
| 593 |
-
})();
|
|
|
|
| 594 |
"""
|
| 595 |
|
| 596 |
with gr.Blocks(theme=gr.themes.Soft(), title="SmartDoc AI", css=css, js=js) as demo:
|
|
|
|
| 517 |
margin-bottom: 16px !important;
|
| 518 |
}
|
| 519 |
"""
|
| 520 |
+
js = r"""
|
| 521 |
+
(() => {
|
| 522 |
+
const uploadMessages = [
|
| 523 |
"Crunching your documents...",
|
| 524 |
"Warming up the AI...",
|
| 525 |
"Extracting knowledge...",
|
|
|
|
| 532 |
"Almost ready..."
|
| 533 |
];
|
| 534 |
|
| 535 |
+
let msgInterval = null;
|
| 536 |
+
let timerInterval = null;
|
| 537 |
+
let startMs = 0;
|
| 538 |
+
let lastMsg = null;
|
| 539 |
|
| 540 |
+
const root = () => document.getElementById("processing-message");
|
| 541 |
+
const isVisible = (el) => !!(el && (el.offsetWidth || el.offsetHeight || el.getClientRects().length));
|
| 542 |
|
| 543 |
+
const pickMsg = () => {
|
| 544 |
if (uploadMessages.length === 0) return "";
|
| 545 |
if (uploadMessages.length === 1) return uploadMessages[0];
|
| 546 |
+
let m;
|
| 547 |
do { m = uploadMessages[Math.floor(Math.random() * uploadMessages.length)]; }
|
| 548 |
while (m === lastMsg);
|
| 549 |
lastMsg = m;
|
| 550 |
return m;
|
| 551 |
+
};
|
| 552 |
|
| 553 |
+
const getMsgSpan = () => root()?.querySelector("#processing-msg");
|
| 554 |
+
const getTimerSpan = () => root()?.querySelector("#processing-timer");
|
| 555 |
|
| 556 |
+
const setMsg = (t) => { const s = getMsgSpan(); if (s) s.textContent = t; };
|
| 557 |
+
const fmtElapsed = () => `${((Date.now() - startMs) / 1000).toFixed(1)}s elapsed`;
|
| 558 |
|
| 559 |
+
const start = () => {
|
| 560 |
if (msgInterval || timerInterval) return;
|
| 561 |
startMs = Date.now();
|
| 562 |
setMsg(pickMsg());
|
| 563 |
|
| 564 |
+
msgInterval = setInterval(() => setMsg(pickMsg()), 2000);
|
| 565 |
|
| 566 |
+
const t = getTimerSpan();
|
| 567 |
if (t) {
|
| 568 |
t.textContent = fmtElapsed();
|
| 569 |
+
timerInterval = setInterval(() => { t.textContent = fmtElapsed(); }, 200);
|
| 570 |
}
|
| 571 |
+
};
|
| 572 |
|
| 573 |
+
const stop = () => {
|
| 574 |
if (msgInterval) { clearInterval(msgInterval); msgInterval = null; }
|
| 575 |
if (timerInterval) { clearInterval(timerInterval); timerInterval = null; }
|
| 576 |
+
const t = getTimerSpan();
|
| 577 |
if (t) t.textContent = "";
|
| 578 |
+
};
|
| 579 |
|
| 580 |
+
const tick = () => {
|
| 581 |
+
const r = root();
|
| 582 |
if (isVisible(r)) start();
|
| 583 |
else stop();
|
| 584 |
+
};
|
| 585 |
|
| 586 |
+
const obs = new MutationObserver(tick);
|
| 587 |
+
obs.observe(document.body, { subtree: true, childList: true, attributes: true });
|
|
|
|
|
|
|
| 588 |
|
| 589 |
window.addEventListener("load", tick);
|
| 590 |
+
setInterval(tick, 500); // fallback
|
| 591 |
+
})();
|
| 592 |
+
|
| 593 |
"""
|
| 594 |
|
| 595 |
with gr.Blocks(theme=gr.themes.Soft(), title="SmartDoc AI", css=css, js=js) as demo:
|