Spaces:
Build error
Build error
Update components/chat.py
Browse files- components/chat.py +39 -0
components/chat.py
CHANGED
|
@@ -2,6 +2,45 @@ import streamlit as st
|
|
| 2 |
from langchain_core.messages import HumanMessage, AIMessage
|
| 3 |
from utils.database import verify_vector_store
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
def display_chat_interface():
|
| 6 |
|
| 7 |
|
|
|
|
| 2 |
from langchain_core.messages import HumanMessage, AIMessage
|
| 3 |
from utils.database import verify_vector_store
|
| 4 |
|
| 5 |
+
|
| 6 |
+
def display_vector_store_info():
|
| 7 |
+
"""Display information about the current vector store state."""
|
| 8 |
+
if 'vector_store' not in st.session_state:
|
| 9 |
+
st.info("ℹ️ No documents loaded yet.")
|
| 10 |
+
return
|
| 11 |
+
|
| 12 |
+
try:
|
| 13 |
+
# Get basic stats
|
| 14 |
+
test_query = vector_store.similarity_search("test", k=1)
|
| 15 |
+
doc_count = len(test_query)
|
| 16 |
+
|
| 17 |
+
# Create an expander for detailed info
|
| 18 |
+
with st.expander("📊 Knowledge Base Status"):
|
| 19 |
+
col1, col2 = st.columns(2)
|
| 20 |
+
|
| 21 |
+
with col1:
|
| 22 |
+
st.metric(
|
| 23 |
+
label="Documents Loaded",
|
| 24 |
+
value=doc_count
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
with col2:
|
| 28 |
+
st.metric(
|
| 29 |
+
label="System Status",
|
| 30 |
+
value="Ready" if verify_vector_store(vector_store) else "Not Ready"
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
# Display sample queries
|
| 34 |
+
if verify_vector_store(vector_store):
|
| 35 |
+
st.markdown("### 🔍 Sample Document Snippets")
|
| 36 |
+
sample_docs = vector_store.similarity_search("", k=3)
|
| 37 |
+
for i, doc in enumerate(sample_docs, 1):
|
| 38 |
+
with st.container():
|
| 39 |
+
st.markdown(f"**Snippet {i}:**")
|
| 40 |
+
st.text(doc.page_content[:200] + "...")
|
| 41 |
+
|
| 42 |
+
except Exception as e:
|
| 43 |
+
st.error(f"Error displaying vector store info: {e}")
|
| 44 |
def display_chat_interface():
|
| 45 |
|
| 46 |
|