Download app.py from rcs3/Codebot: direct link, hf CLI and curl.
- Browser
- Download file 3.38 kB
-
https://huggingface.co/spaces/rcs3/Codebot/resolve/main/app.py
- Command line
-
hf download hf://spaces/rcs3/Codebot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/rcs3/Codebot/resolve/main/app.py
3.38 kB
| import streamlit as st | |
| from repochat.utils import init_session_state | |
| from repochat.git import git_form | |
| from repochat.db import vector_db, load_to_db | |
| from repochat.models import hf_embeddings, groq_llm | |
| from repochat.chain import response_chain | |
| st.set_page_config( | |
| page_title="Codebot", | |
| page_icon="π»", | |
| layout="wide", | |
| initial_sidebar_state="expanded", | |
| ) | |
| init_session_state() | |
| # ββ Header ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| st.markdown( | |
| """ | |
| <div style='text-align:center; padding: 1rem 0 0.5rem;'> | |
| <h1 style='font-size:2.2rem; margin-bottom:0;'>π» Codebot</h1> | |
| <p style='color:gray; font-size:1rem; margin-top:0.25rem;'> | |
| Chat with any GitHub repository using RAG + Llama 3 | |
| </p> | |
| </div> | |
| """, | |
| unsafe_allow_html=True, | |
| ) | |
| # ββ Sidebar: GitHub form βββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| try: | |
| result = git_form(st.session_state["repo_path"]) | |
| if result: | |
| db_name, submitted = result | |
| st.session_state["db_name"] = db_name | |
| if submitted and not st.session_state["db_loaded"]: | |
| with st.spinner("π Loading repository files into vector databaseβ¦"): | |
| st.session_state["chroma_db"] = vector_db( | |
| hf_embeddings(), | |
| load_to_db(st.session_state["repo_path"]), | |
| ) | |
| with st.spinner("π€ Initialising LLM chainβ¦"): | |
| st.session_state["qa"] = response_chain( | |
| db=st.session_state["chroma_db"], | |
| llm=groq_llm(), | |
| ) | |
| st.session_state["db_loaded"] = True | |
| st.success(f"β Ready! Ask anything about **{db_name.replace('_', '/')}**") | |
| except TypeError: | |
| pass | |
| # ββ Chat area βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| if not st.session_state["db_loaded"]: | |
| st.info("π Paste a public GitHub repository URL in the sidebar to get started.") | |
| else: | |
| # Render chat history | |
| for message in st.session_state["messages"]: | |
| with st.chat_message(message["role"]): | |
| st.markdown(message["content"]) | |
| # New user input | |
| if prompt := st.chat_input("Ask about the codebaseβ¦"): | |
| st.session_state["messages"].append({"role": "user", "content": prompt}) | |
| with st.chat_message("user"): | |
| st.markdown(prompt) | |
| with st.chat_message("assistant"): | |
| with st.spinner("Thinkingβ¦"): | |
| result = st.session_state["qa"].invoke({"question": prompt}) | |
| answer = result.get("answer", result.get("result", "Sorry, I couldn't generate a response.")) | |
| st.markdown(answer) | |
| st.session_state["messages"].append({"role": "assistant", "content": answer}) | |
| # Clear chat button | |
| if st.session_state["messages"]: | |
| if st.button("ποΈ Clear chat", use_container_width=False): | |
| st.session_state["messages"] = [] | |
| st.rerun() |