kpawargi commited on
Commit
a310bdb
Β·
verified Β·
1 Parent(s): 3904554

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -9
app.py CHANGED
@@ -73,12 +73,24 @@ if uploaded_file:
73
  user_question = st.text_input("πŸ’¬ Type your question here")
74
 
75
  if user_question:
76
- with st.spinner("Thinking..."):
77
- answer = astra_vector_index.query(user_question, llm=llm).strip()
78
- st.markdown(f"### 🧠 Answer:\n{answer}")
79
-
80
- st.markdown("### πŸ” Top Relevant Chunks")
81
- docs = vector_store.similarity_search_with_score(user_question, k=4)
82
- for i, (doc, score) in enumerate(docs, 1):
83
- st.markdown(f"**Chunk {i}** β€” Relevance Score: `{score:.4f}`")
84
- st.code(doc.page_content[:500], language="markdown")
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  user_question = st.text_input("πŸ’¬ Type your question here")
74
 
75
  if user_question:
76
+ with st.spinner("🧠 Thinking..."):
77
+ try:
78
+ # Optional: show what documents are retrieved before sending to LLM
79
+ retrieved_docs = vector_store.similarity_search(user_question, k=4)
80
+ if not retrieved_docs:
81
+ st.warning("⚠️ No relevant text chunks found for this question. Try a different question.")
82
+ else:
83
+ st.markdown("### πŸ” Top Relevant Chunks (raw):")
84
+ for i, doc in enumerate(retrieved_docs, 1):
85
+ st.code(doc.page_content[:300], language="markdown")
86
+
87
+
88
+ answer = astra_vector_index.query(user_question, llm=llm)
89
+ if answer.strip():
90
+ st.markdown("### 🧠 Answer:")
91
+ st.write(answer.strip())
92
+ else:
93
+ st.warning("⚠️ The model returned an empty response. Try rephrasing the question or check your model/API key.")
94
+ except Exception as e:
95
+ st.error(f"🚨 Error while generating response:\n\n{str(e)}")
96
+