Spaces:
Runtime error
Runtime error
import streamlit as st | |
from time import sleep | |
from retriever import load_vector_store | |
from langgraph_graph import generate_answer | |
st.set_page_config("MedMCQA Chatbot", page_icon="π©Ί") | |
# π Sidebar | |
with st.sidebar: | |
st.title("π©Ί MedMCQA Chatbot") | |
theme_mode = st.radio("π Theme", ["Light", "Dark"], horizontal=True) | |
# π Theme | |
if theme_mode == "Dark": | |
st.markdown(""" | |
<style> | |
body, .stApp { background-color: #1e1e1e !important; color: #eee !important; } | |
.stTextInput input { background-color: #333 !important; color: #eee !important; } | |
input::placeholder { color: #bbb !important; } | |
.stButton>button { background-color: #444 !important; color: #eee !important; } | |
</style> | |
""", unsafe_allow_html=True) | |
else: | |
st.markdown(""" | |
<style> | |
body, .stApp { background-color: #ffffff !important; color: #111 !important; } | |
.stTextInput input { background-color: #f0f0f0 !important; color: #111 !important; } | |
input::placeholder { color: #444 !important; } | |
.stButton>button { background-color: #e0e0e0 !important; color: #111 !important; } | |
</style> | |
""", unsafe_allow_html=True) | |
st.header("π©Ί MedMCQA Chatbot") | |
st.caption("Ask a medical question and get answers from the MedMCQA dataset only. If not found, it will respond gracefully.") | |
# β Cache FAISS loading to avoid blocking | |
def get_vector_store(): | |
return load_vector_store() | |
# Load vector store in the background | |
db = get_vector_store() | |
# βοΈ Query | |
query = st.text_input("π Enter your medical question:", | |
placeholder="e.g., What is the mechanism of Aspirin?") | |
# π Answer generation | |
if query: | |
results = db.similarity_search(query, k=3) | |
context = "\n\n".join([doc.page_content for doc in results]) | |
with st.spinner("π§ Generating answer..."): | |
response = generate_answer(query, context) | |
# Animated answer | |
st.markdown("<h4>π§ Answer:</h4>", unsafe_allow_html=True) | |
answer_placeholder = st.empty() | |
final_text = "" | |
for char in response: | |
final_text += char | |
answer_placeholder.markdown(final_text) | |
sleep(0.01) | |
with st.expander("π Top Matches"): | |
for i, doc in enumerate(results, 1): | |
st.markdown(f"**Result {i}:**\n\n{doc.page_content}") | |
# π¬ Sidebar Contact | |
with st.sidebar: | |
st.markdown("---") | |
st.markdown("### π¬ Contact") | |
st.markdown("[π§ Email](mailto:[email protected])") | |
st.markdown("[π LinkedIn](https://linkedin.com/in/sankethhonavar)") | |
st.markdown("[π» GitHub](https://github.com/SankethHonavar)") | |