Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -636,12 +636,7 @@ def generate_response_streaming(prompt: str, doc_snippets: str, has_docs: bool):
|
|
| 636 |
yield delta.content
|
| 637 |
except Exception as e:
|
| 638 |
em = str(e).lower()
|
| 639 |
-
|
| 640 |
-
import traceback
|
| 641 |
-
error_details = f"{type(e).__name__}: {str(e)}"
|
| 642 |
-
st.error(f"DEBUG: {error_details}")
|
| 643 |
-
st.code(traceback.format_exc())
|
| 644 |
-
|
| 645 |
if "model is loading" in em:
|
| 646 |
yield "⏳ The model is warming up. Please try again in ~30 seconds."
|
| 647 |
elif "rate limit" in em or "too many requests" in em:
|
|
@@ -649,6 +644,9 @@ def generate_response_streaming(prompt: str, doc_snippets: str, has_docs: bool):
|
|
| 649 |
else:
|
| 650 |
yield f"Error: {error_details}"
|
| 651 |
|
|
|
|
|
|
|
|
|
|
| 652 |
# =========================
|
| 653 |
# Session init
|
| 654 |
# =========================
|
|
@@ -662,7 +660,8 @@ if "pdf_files" not in st.session_state:
|
|
| 662 |
st.session_state.pdf_files = get_pdf_files()
|
| 663 |
if "vectorstore" not in st.session_state:
|
| 664 |
st.session_state.vectorstore = None
|
| 665 |
-
|
|
|
|
| 666 |
|
| 667 |
# =========================
|
| 668 |
# Styling
|
|
@@ -727,11 +726,12 @@ with st.sidebar:
|
|
| 727 |
else:
|
| 728 |
st.write("No PDF files found")
|
| 729 |
|
| 730 |
-
# AUTO-LOAD VECTORSTORE ON FIRST RUN
|
| 731 |
-
if st.session_state.
|
| 732 |
with st.spinner("📚 Loading knowledge base..."):
|
| 733 |
st.session_state.vectorstore = ensure_vectorstore(st.session_state.pdf_files)
|
| 734 |
-
|
|
|
|
| 735 |
# Welcome message
|
| 736 |
if not st.session_state.messages:
|
| 737 |
topics = get_document_topics(st.session_state.pdf_files)
|
|
|
|
| 636 |
yield delta.content
|
| 637 |
except Exception as e:
|
| 638 |
em = str(e).lower()
|
| 639 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 640 |
if "model is loading" in em:
|
| 641 |
yield "⏳ The model is warming up. Please try again in ~30 seconds."
|
| 642 |
elif "rate limit" in em or "too many requests" in em:
|
|
|
|
| 644 |
else:
|
| 645 |
yield f"Error: {error_details}"
|
| 646 |
|
| 647 |
+
# =========================
|
| 648 |
+
# Session init
|
| 649 |
+
# =========================
|
| 650 |
# =========================
|
| 651 |
# Session init
|
| 652 |
# =========================
|
|
|
|
| 660 |
st.session_state.pdf_files = get_pdf_files()
|
| 661 |
if "vectorstore" not in st.session_state:
|
| 662 |
st.session_state.vectorstore = None
|
| 663 |
+
if "vectorstore_loaded" not in st.session_state: # ← NEW FLAG
|
| 664 |
+
st.session_state.vectorstore_loaded = False
|
| 665 |
|
| 666 |
# =========================
|
| 667 |
# Styling
|
|
|
|
| 726 |
else:
|
| 727 |
st.write("No PDF files found")
|
| 728 |
|
| 729 |
+
# AUTO-LOAD VECTORSTORE ON FIRST RUN (ONLY ONCE)
|
| 730 |
+
if not st.session_state.vectorstore_loaded and st.session_state.pdf_files:
|
| 731 |
with st.spinner("📚 Loading knowledge base..."):
|
| 732 |
st.session_state.vectorstore = ensure_vectorstore(st.session_state.pdf_files)
|
| 733 |
+
if st.session_state.vectorstore is not None:
|
| 734 |
+
st.session_state.vectorstore_loaded = True # ← Mark as loaded
|
| 735 |
# Welcome message
|
| 736 |
if not st.session_state.messages:
|
| 737 |
topics = get_document_topics(st.session_state.pdf_files)
|