qna interface bug fix
Browse files
app.py
CHANGED
@@ -293,6 +293,9 @@ def main():
|
|
293 |
/* Feature cards for homepage */
|
294 |
.feature-card {background-color: rgba(255, 255, 255, 0.1); color: inherit; border-radius: 10px; padding: 20px; min-height: 220px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); display: flex; flex-direction: column; align-items: center;}
|
295 |
.feature-card p {font-size: 0.9em; margin-top: 5px; max-width: 100%; overflow-wrap: break-word; word-wrap: break-word;}
|
|
|
|
|
|
|
296 |
</style>
|
297 |
""", unsafe_allow_html=True)
|
298 |
|
@@ -378,6 +381,10 @@ def main():
|
|
378 |
|
379 |
# Chat interface
|
380 |
elif st.session_state.page == 'chat':
|
|
|
|
|
|
|
|
|
381 |
# Header with clear button
|
382 |
col1, col2 = st.columns([3, 1])
|
383 |
with col1:
|
@@ -386,41 +393,22 @@ def main():
|
|
386 |
# Add a clear button in the header
|
387 |
if st.button("ποΈ Clear Chat"):
|
388 |
st.session_state.chat_history = []
|
|
|
389 |
st.rerun()
|
390 |
-
|
391 |
st.markdown("Ask any clinical diagnostic question and get insights based on medical knowledge and patient cases.")
|
392 |
|
393 |
-
#
|
394 |
-
|
395 |
-
st.markdown(
|
396 |
-
|
397 |
-
st.
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
st.markdown(f"<div class='source-box'>"
|
402 |
-
f"<b>Source:</b> {Path(doc.metadata['source']).stem}<br>"
|
403 |
-
f"<b>Type:</b> {doc.metadata['type']}<br>"
|
404 |
-
f"<b>Content:</b> {doc.page_content[:300]}...</div>",
|
405 |
-
unsafe_allow_html=True)
|
406 |
-
|
407 |
-
# Show evaluation metrics if available
|
408 |
-
try:
|
409 |
-
eval_scores = evaluate_rag_response(response, embeddings)
|
410 |
-
with st.expander("View Evaluation Metrics"):
|
411 |
-
col1, col2 = st.columns(2)
|
412 |
-
with col1:
|
413 |
-
st.metric("Hit Rate (Top-3)", f"{eval_scores['hit_rate']:.2f}")
|
414 |
-
with col2:
|
415 |
-
st.metric("Faithfulness", f"{eval_scores['faithfulness']:.2f}")
|
416 |
-
except Exception as e:
|
417 |
-
st.warning(f"Evaluation metrics unavailable: {str(e)}")
|
418 |
|
419 |
-
#
|
420 |
-
|
421 |
-
col1, col2 = st.columns([1, 5])
|
422 |
-
with col1:
|
423 |
-
submit_button = st.button("Submit")
|
424 |
|
425 |
# Process query
|
426 |
if submit_button and user_input:
|
@@ -439,10 +427,40 @@ def main():
|
|
439 |
# Add to chat history
|
440 |
st.session_state.chat_history.append((user_input, response))
|
441 |
|
|
|
|
|
|
|
442 |
# Rerun to update UI
|
443 |
st.rerun()
|
444 |
except Exception as e:
|
445 |
st.error(f"Error processing query: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
446 |
|
447 |
# About page
|
448 |
elif st.session_state.page == 'about':
|
|
|
293 |
/* Feature cards for homepage */
|
294 |
.feature-card {background-color: rgba(255, 255, 255, 0.1); color: inherit; border-radius: 10px; padding: 20px; min-height: 220px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); display: flex; flex-direction: column; align-items: center;}
|
295 |
.feature-card p {font-size: 0.9em; margin-top: 5px; max-width: 100%; overflow-wrap: break-word; word-wrap: break-word;}
|
296 |
+
|
297 |
+
/* Fixed input container */
|
298 |
+
.input-container {margin-bottom: 20px; padding: 15px; border-radius: 10px; background-color: rgba(255, 255, 255, 0.05); border: 1px solid rgba(255, 255, 255, 0.1);}
|
299 |
</style>
|
300 |
""", unsafe_allow_html=True)
|
301 |
|
|
|
381 |
|
382 |
# Chat interface
|
383 |
elif st.session_state.page == 'chat':
|
384 |
+
# Initialize session state for input if not exists
|
385 |
+
if 'user_input' not in st.session_state:
|
386 |
+
st.session_state.user_input = ""
|
387 |
+
|
388 |
# Header with clear button
|
389 |
col1, col2 = st.columns([3, 1])
|
390 |
with col1:
|
|
|
393 |
# Add a clear button in the header
|
394 |
if st.button("ποΈ Clear Chat"):
|
395 |
st.session_state.chat_history = []
|
396 |
+
st.session_state.user_input = ""
|
397 |
st.rerun()
|
398 |
+
|
399 |
st.markdown("Ask any clinical diagnostic question and get insights based on medical knowledge and patient cases.")
|
400 |
|
401 |
+
# Fixed input area at the top
|
402 |
+
with st.container():
|
403 |
+
st.markdown("<div class='input-container'>", unsafe_allow_html=True)
|
404 |
+
user_input = st.text_area("Ask a clinical question:", st.session_state.user_input, height=100, key="question_input")
|
405 |
+
col1, col2 = st.columns([1, 5])
|
406 |
+
with col1:
|
407 |
+
submit_button = st.button("Submit")
|
408 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
409 |
|
410 |
+
# Create a container for chat history
|
411 |
+
chat_container = st.container()
|
|
|
|
|
|
|
412 |
|
413 |
# Process query
|
414 |
if submit_button and user_input:
|
|
|
427 |
# Add to chat history
|
428 |
st.session_state.chat_history.append((user_input, response))
|
429 |
|
430 |
+
# Clear the input field
|
431 |
+
st.session_state.user_input = ""
|
432 |
+
|
433 |
# Rerun to update UI
|
434 |
st.rerun()
|
435 |
except Exception as e:
|
436 |
st.error(f"Error processing query: {str(e)}")
|
437 |
+
|
438 |
+
# Display chat history in the container
|
439 |
+
with chat_container:
|
440 |
+
for i, (query, response) in enumerate(st.session_state.chat_history):
|
441 |
+
st.markdown(f"<div class='chat-message chat-message-user'><b>π§ββοΈ You:</b> {query}</div>", unsafe_allow_html=True)
|
442 |
+
|
443 |
+
st.markdown(f"<div class='chat-message chat-message-assistant'><b>π©Ί DiReCT:</b> {response['answer']}</div>", unsafe_allow_html=True)
|
444 |
+
|
445 |
+
with st.expander("View Sources"):
|
446 |
+
for doc in response["context"]:
|
447 |
+
st.markdown(f"<div class='source-box'>"
|
448 |
+
f"<b>Source:</b> {Path(doc.metadata['source']).stem}<br>"
|
449 |
+
f"<b>Type:</b> {doc.metadata['type']}<br>"
|
450 |
+
f"<b>Content:</b> {doc.page_content[:300]}...</div>",
|
451 |
+
unsafe_allow_html=True)
|
452 |
+
|
453 |
+
# Show evaluation metrics if available
|
454 |
+
try:
|
455 |
+
eval_scores = evaluate_rag_response(response, embeddings)
|
456 |
+
with st.expander("View Evaluation Metrics"):
|
457 |
+
col1, col2 = st.columns(2)
|
458 |
+
with col1:
|
459 |
+
st.metric("Hit Rate (Top-3)", f"{eval_scores['hit_rate']:.2f}")
|
460 |
+
with col2:
|
461 |
+
st.metric("Faithfulness", f"{eval_scores['faithfulness']:.2f}")
|
462 |
+
except Exception as e:
|
463 |
+
st.warning(f"Evaluation metrics unavailable: {str(e)}")
|
464 |
|
465 |
# About page
|
466 |
elif st.session_state.page == 'about':
|