Download app.py from shani67/DSA2: direct link, hf CLI and curl.
- Browser
- Download file 3.31 kB
-
https://huggingface.co/spaces/shani67/DSA2/resolve/main/app.py
- Command line
-
hf download hf://spaces/shani67/DSA2/app.py
-
curl -L -o app.py https://huggingface.co/spaces/shani67/DSA2/resolve/main/app.py
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 | |
| # ===================================================== | |
| 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() |