Spaces:
Sleeping
Sleeping
fixed answer issue
Browse files- app.py +20 -20
- chroma_db/chroma.sqlite3 +1 -1
app.py
CHANGED
|
@@ -271,19 +271,18 @@ ANSWER:"""
|
|
| 271 |
st.error("OpenAI client not initialized. Please provide a valid API key.")
|
| 272 |
return None, []
|
| 273 |
|
| 274 |
-
#
|
| 275 |
-
with st.spinner("
|
|
|
|
| 276 |
retrieved_chunks = self.retrieve_relevant_chunks(user_question, n_chunks)
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
with st.spinner("π Preparing context..."):
|
| 283 |
rag_prompt = self.create_rag_prompt(user_question, retrieved_chunks)
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
with st.spinner("π€ Generating answer..."):
|
| 287 |
answer = self.generate_answer(rag_prompt, model)
|
| 288 |
|
| 289 |
# Extract source URLs
|
|
@@ -394,8 +393,13 @@ def main():
|
|
| 394 |
with col1:
|
| 395 |
st.header("π¬ Ask Your Question")
|
| 396 |
|
| 397 |
-
# Question input
|
| 398 |
-
default_question =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 399 |
user_question = st.text_input(
|
| 400 |
"Enter your question about Scikit-learn:",
|
| 401 |
value=default_question,
|
|
@@ -403,10 +407,6 @@ def main():
|
|
| 403 |
key="question_input"
|
| 404 |
)
|
| 405 |
|
| 406 |
-
# Clear selected question after using it
|
| 407 |
-
if 'selected_question' in st.session_state:
|
| 408 |
-
del st.session_state['selected_question']
|
| 409 |
-
|
| 410 |
# Submit button
|
| 411 |
submit_button = st.button("π Get Answer", type="primary")
|
| 412 |
|
|
@@ -428,8 +428,8 @@ def main():
|
|
| 428 |
'sources': sources
|
| 429 |
})
|
| 430 |
|
| 431 |
-
#
|
| 432 |
-
st.
|
| 433 |
|
| 434 |
# Display chat history
|
| 435 |
if st.session_state.chat_history:
|
|
@@ -464,7 +464,7 @@ def main():
|
|
| 464 |
|
| 465 |
for question in example_questions:
|
| 466 |
if st.button(question, key=f"example_{hash(question)}"):
|
| 467 |
-
#
|
| 468 |
st.session_state['selected_question'] = question
|
| 469 |
st.rerun()
|
| 470 |
|
|
|
|
| 271 |
st.error("OpenAI client not initialized. Please provide a valid API key.")
|
| 272 |
return None, []
|
| 273 |
|
| 274 |
+
# Use a single spinner for the entire process to prevent flickering
|
| 275 |
+
with st.spinner("π€ Generating answer..."):
|
| 276 |
+
# Step 1: Retrieve relevant chunks
|
| 277 |
retrieved_chunks = self.retrieve_relevant_chunks(user_question, n_chunks)
|
| 278 |
+
|
| 279 |
+
if not retrieved_chunks:
|
| 280 |
+
return "I couldn't find relevant information in the Scikit-learn documentation to answer your question. Please try rephrasing your question or ask about a different topic.", []
|
| 281 |
+
|
| 282 |
+
# Step 2: Create augmented prompt
|
|
|
|
| 283 |
rag_prompt = self.create_rag_prompt(user_question, retrieved_chunks)
|
| 284 |
+
|
| 285 |
+
# Step 3: Generate answer
|
|
|
|
| 286 |
answer = self.generate_answer(rag_prompt, model)
|
| 287 |
|
| 288 |
# Extract source URLs
|
|
|
|
| 393 |
with col1:
|
| 394 |
st.header("π¬ Ask Your Question")
|
| 395 |
|
| 396 |
+
# Question input with better state management
|
| 397 |
+
default_question = ''
|
| 398 |
+
if 'selected_question' in st.session_state:
|
| 399 |
+
default_question = st.session_state['selected_question']
|
| 400 |
+
# Clear after getting the value to prevent re-triggering
|
| 401 |
+
del st.session_state['selected_question']
|
| 402 |
+
|
| 403 |
user_question = st.text_input(
|
| 404 |
"Enter your question about Scikit-learn:",
|
| 405 |
value=default_question,
|
|
|
|
| 407 |
key="question_input"
|
| 408 |
)
|
| 409 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 410 |
# Submit button
|
| 411 |
submit_button = st.button("π Get Answer", type="primary")
|
| 412 |
|
|
|
|
| 428 |
'sources': sources
|
| 429 |
})
|
| 430 |
|
| 431 |
+
# Success message instead of rerun to prevent flickering
|
| 432 |
+
st.success("β
Answer generated successfully! Check the chat history below.")
|
| 433 |
|
| 434 |
# Display chat history
|
| 435 |
if st.session_state.chat_history:
|
|
|
|
| 464 |
|
| 465 |
for question in example_questions:
|
| 466 |
if st.button(question, key=f"example_{hash(question)}"):
|
| 467 |
+
# Set the question and rerun only once
|
| 468 |
st.session_state['selected_question'] = question
|
| 469 |
st.rerun()
|
| 470 |
|
chroma_db/chroma.sqlite3
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 13279232
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:29dd849ea2bda952a956fc1ae9039fcc202dd536fba5f36beb87b2da0bb04c99
|
| 3 |
size 13279232
|