Spaces:
Sleeping
Sleeping
fix
Browse files
main.py
CHANGED
|
@@ -517,92 +517,85 @@ def main():
|
|
| 517 |
margin-bottom: 16px !important;
|
| 518 |
}
|
| 519 |
"""
|
| 520 |
-
js = r
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
return document.getElementById("processing-message");
|
| 541 |
-
}
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
}
|
| 562 |
-
function setMsg(t) {
|
| 563 |
-
const s = getMsgSpan();
|
| 564 |
-
if (s) s.textContent = t;
|
| 565 |
-
}
|
| 566 |
-
function fmtElapsed() {
|
| 567 |
-
return ((Date.now() - startMs) / 1000).toFixed(1) + "s elapsed";
|
| 568 |
-
}
|
| 569 |
|
| 570 |
-
function start() {
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
|
| 575 |
-
|
| 576 |
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
|
|
|
| 581 |
}
|
| 582 |
-
}
|
| 583 |
|
| 584 |
-
function stop() {
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
}
|
| 590 |
|
| 591 |
-
function tick() {
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
}
|
| 596 |
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
obs.observe(document.body, { subtree: true, childList: true, attributes: true });
|
| 600 |
|
| 601 |
-
window.addEventListener("load", tick);
|
| 602 |
-
setInterval(tick, 500);
|
| 603 |
-
|
|
|
|
| 604 |
|
| 605 |
-
with gr.Blocks(theme=gr.themes.Soft(), title="SmartDoc AI", css=css
|
| 606 |
gr.Markdown("### SmartDoc AI - Document Q&A", elem_classes="app-title")
|
| 607 |
gr.Markdown("Upload your documents and ask questions. Answers will appear below, just like a chat.", elem_classes="app-description")
|
| 608 |
gr.Markdown("---")
|
|
@@ -888,19 +881,19 @@ setInterval(tick, 500);
|
|
| 888 |
# Launch server - Compatible with both local and Hugging Face Spaces
|
| 889 |
# HF Spaces sets SPACE_ID environment variable
|
| 890 |
is_hf_space = os.environ.get("SPACE_ID") is not None
|
| 891 |
-
|
| 892 |
demo.queue()
|
| 893 |
if is_hf_space:
|
| 894 |
# Hugging Face Spaces configuration
|
| 895 |
logger.info("Running on Hugging Face Spaces")
|
| 896 |
-
demo.launch(server_name="0.0.0.0", server_port=7860)
|
| 897 |
else:
|
| 898 |
# Local development configuration
|
| 899 |
configured_port = int(os.environ.get("GRADIO_SERVER_PORT", "7860"))
|
| 900 |
server_port = _find_open_port(configured_port)
|
| 901 |
logger.info(f"Launching Gradio on port {server_port}")
|
| 902 |
logger.info(f"Access the app at: http://127.0.0.1:{server_port}")
|
| 903 |
-
demo.launch(server_name="127.0.0.1", server_port=server_port, share=False)
|
|
|
|
| 904 |
|
| 905 |
|
| 906 |
if __name__ == "__main__":
|
|
|
|
| 517 |
margin-bottom: 16px !important;
|
| 518 |
}
|
| 519 |
"""
|
| 520 |
+
js = r"""
|
| 521 |
+
(function () {
|
| 522 |
+
var uploadMessages = [
|
| 523 |
+
"Crunching your documents...",
|
| 524 |
+
"Warming up the AI...",
|
| 525 |
+
"Extracting knowledge...",
|
| 526 |
+
"Scanning for insights...",
|
| 527 |
+
"Preparing your data...",
|
| 528 |
+
"Looking for answers...",
|
| 529 |
+
"Analyzing file structure...",
|
| 530 |
+
"Reading your files...",
|
| 531 |
+
"Indexing content...",
|
| 532 |
+
"Almost ready..."
|
| 533 |
+
];
|
| 534 |
+
|
| 535 |
+
var msgInterval = null;
|
| 536 |
+
var timerInterval = null;
|
| 537 |
+
var startMs = 0;
|
| 538 |
+
var lastMsg = null;
|
| 539 |
+
|
| 540 |
+
function root() { return document.getElementById("processing-message"); }
|
| 541 |
+
function isVisible(el) { return !!(el && (el.offsetWidth || el.offsetHeight || el.getClientRects().length)); }
|
| 542 |
+
|
| 543 |
+
function pickMsg() {
|
| 544 |
+
if (uploadMessages.length === 0) return "";
|
| 545 |
+
if (uploadMessages.length === 1) return uploadMessages[0];
|
| 546 |
+
var m;
|
| 547 |
+
do { m = uploadMessages[Math.floor(Math.random() * uploadMessages.length)]; }
|
| 548 |
+
while (m === lastMsg);
|
| 549 |
+
lastMsg = m;
|
| 550 |
+
return m;
|
| 551 |
+
}
|
| 552 |
+
|
| 553 |
+
function getMsgSpan() {
|
| 554 |
+
return document.getElementById("processing-msg") || (root() ? root().querySelector("#processing-msg") : null);
|
| 555 |
+
}
|
| 556 |
+
function getTimerSpan() {
|
| 557 |
+
return document.getElementById("processing-timer") || (root() ? root().querySelector("#processing-timer") : null);
|
| 558 |
+
}
|
| 559 |
+
|
| 560 |
+
function setMsg(t) { var s = getMsgSpan(); if (s) s.textContent = t; }
|
| 561 |
+
function fmtElapsed() { return ((Date.now() - startMs) / 1000).toFixed(1) + "s elapsed"; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 562 |
|
| 563 |
+
function start() {
|
| 564 |
+
if (msgInterval || timerInterval) return;
|
| 565 |
+
startMs = Date.now();
|
| 566 |
+
setMsg(pickMsg());
|
| 567 |
|
| 568 |
+
msgInterval = setInterval(function(){ setMsg(pickMsg()); }, 2000);
|
| 569 |
|
| 570 |
+
var t = getTimerSpan();
|
| 571 |
+
if (t) {
|
| 572 |
+
t.textContent = fmtElapsed();
|
| 573 |
+
timerInterval = setInterval(function(){ t.textContent = fmtElapsed(); }, 200);
|
| 574 |
+
}
|
| 575 |
}
|
|
|
|
| 576 |
|
| 577 |
+
function stop() {
|
| 578 |
+
if (msgInterval) { clearInterval(msgInterval); msgInterval = null; }
|
| 579 |
+
if (timerInterval) { clearInterval(timerInterval); timerInterval = null; }
|
| 580 |
+
var t = getTimerSpan();
|
| 581 |
+
if (t) t.textContent = "";
|
| 582 |
+
}
|
| 583 |
|
| 584 |
+
function tick() {
|
| 585 |
+
var r = root();
|
| 586 |
+
if (isVisible(r)) start();
|
| 587 |
+
else stop();
|
| 588 |
+
}
|
| 589 |
|
| 590 |
+
var obs = new MutationObserver(tick);
|
| 591 |
+
obs.observe(document.body, { subtree: true, childList: true, attributes: true });
|
|
|
|
| 592 |
|
| 593 |
+
window.addEventListener("load", tick);
|
| 594 |
+
setInterval(tick, 500);
|
| 595 |
+
})();
|
| 596 |
+
"""
|
| 597 |
|
| 598 |
+
with gr.Blocks(theme=gr.themes.Soft(), title="SmartDoc AI", css=css) as demo:
|
| 599 |
gr.Markdown("### SmartDoc AI - Document Q&A", elem_classes="app-title")
|
| 600 |
gr.Markdown("Upload your documents and ask questions. Answers will appear below, just like a chat.", elem_classes="app-description")
|
| 601 |
gr.Markdown("---")
|
|
|
|
| 881 |
# Launch server - Compatible with both local and Hugging Face Spaces
|
| 882 |
# HF Spaces sets SPACE_ID environment variable
|
| 883 |
is_hf_space = os.environ.get("SPACE_ID") is not None
|
|
|
|
| 884 |
demo.queue()
|
| 885 |
if is_hf_space:
|
| 886 |
# Hugging Face Spaces configuration
|
| 887 |
logger.info("Running on Hugging Face Spaces")
|
| 888 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, js=js)
|
| 889 |
else:
|
| 890 |
# Local development configuration
|
| 891 |
configured_port = int(os.environ.get("GRADIO_SERVER_PORT", "7860"))
|
| 892 |
server_port = _find_open_port(configured_port)
|
| 893 |
logger.info(f"Launching Gradio on port {server_port}")
|
| 894 |
logger.info(f"Access the app at: http://127.0.0.1:{server_port}")
|
| 895 |
+
demo.launch(server_name="127.0.0.1", server_port=server_port, share=False, js=js)
|
| 896 |
+
|
| 897 |
|
| 898 |
|
| 899 |
if __name__ == "__main__":
|