DSA2 / app.py
shani67's picture
Create app.py
300d978 verified
Raw History Blame Contribute Delete
3.31 kB
import streamlit as st
from rag_pipeline import get_qa_chain
# =====================================================
# PAGE CONFIG
# =====================================================
st.set_page_config(
page_title="AlgoPilot",
page_icon="πŸ€–",
layout="wide"
)
# =====================================================
# CUSTOM CSS
# =====================================================
st.markdown("""
<style>
.stApp {
background-color: #0f172a;
color: white;
}
#MainMenu,
footer,
header {
visibility: hidden;
}
.main-title {
text-align: center;
font-size: 52px;
font-weight: 700;
margin-top: 50px;
color: white;
}
.sub-text {
text-align: center;
color: #94a3b8;
font-size: 22px;
margin-bottom: 40px;
}
.user-message {
background: #1e293b;
border-radius: 18px;
padding: 18px;
margin-bottom: 15px;
}
.bot-message {
border-left: 3px solid #38bdf8;
padding: 18px;
margin-bottom: 15px;
}
</style>
""", unsafe_allow_html=True)
# =====================================================
# LOAD QA CHAIN
# =====================================================
@st.cache_resource
def load_chain():
return get_qa_chain()
qa_chain = load_chain()
# =====================================================
# SESSION STATE
# =====================================================
if "messages" not in st.session_state:
st.session_state.messages = []
# =====================================================
# SIDEBAR
# =====================================================
st.sidebar.title("πŸ€– AlgoPilot")
st.sidebar.markdown("""
### πŸ“š Features
- Ask DSA Questions
- Learn Algorithms
- Understand Code
- AI Tutor Assistance
""")
# =====================================================
# TITLE
# =====================================================
st.markdown("""
<div class="main-title">
πŸ€– AlgoPilot
</div>
<div class="sub-text">
Your AI DSA Tutor
</div>
""", unsafe_allow_html=True)
# =====================================================
# CHAT HISTORY
# =====================================================
for msg in st.session_state.messages:
if msg["role"] == "user":
st.markdown(
f"""
<div class="user-message">
<b>πŸ‘€ You</b><br><br>
{msg['content']}
</div>
""",
unsafe_allow_html=True
)
else:
st.markdown(
f"""
<div class="bot-message">
<b>πŸ€– Tutor</b><br><br>
{msg['content']}
</div>
""",
unsafe_allow_html=True
)
# =====================================================
# INPUT
# =====================================================
query = st.chat_input("Ask a DSA question...")
# =====================================================
# RESPONSE
# =====================================================
if query:
st.session_state.messages.append(
{
"role": "user",
"content": query
}
)
with st.spinner("Thinking..."):
response = qa_chain.run(query)
st.session_state.messages.append(
{
"role": "assistant",
"content": response
}
)
st.rerun()