Spaces:
Sleeping
Sleeping
Islam Mamedov commited on
Commit ·
cb2410e
1
Parent(s): 1c5f7c3
Self-building index for Spaces deploy
Browse files12345678910111213141516171812 unmodified lines31323334353617 unmodified lines5455565758596061"""Streamlit UI for the FastAPI Codebase Q&A RAG system.Run locally:export GROQ_API_KEY=gsk_...streamlit run app.pyOn Hugging Face Spaces, set GROQ_API_KEY as a Space secret."""import osimport sysfrom dotenv import load_dotenvload_dotenv(override=True)from pathlib import Pathsys.path.insert(0, str(Path(__file__).parent / "src"))import streamlit as st12 unmodified linesst.set_page_config(page_title="FastAPI Codebase Q&A", page_icon="⚡",layout="wide")st.title("⚡ FastAPI Codebase Q&A")st.caption("Retrieval-augmented answers over FastAPI's source code, docs, ""and GitHub issues — every claim cited, honest refusals when "17 unmodified lines"recall@5 **0.91** · MRR **0.71**\n\n""faithful **0.89** · correct **0.91** · refusal **7/7**")# TODO: replace with your repo URLst.markdown("[Source & write-up](https://github.com/YOUR_USERNAME/codebase-rag)")@st.cache_data(show_spinner=False)123456789101112131415161718192012 unmodified lines333435363738394041424344454647484950515253545556575817 unmodified lines7677787980818283"""Streamlit UI for the FastAPI Codebase Q&A RAG system.Run locally:streamlit run app.py # reads GROQ_API_KEY from .envOn Hugging Face Spaces, set GROQ_API_KEY as a Space secret. The Space hasno prebuilt index, so ensure_index() builds it from data/chunks.jsonl onfirst boot (~3 min, cached afterwards)."""import osimport sysfrom pathlib import Pathfrom dotenv import load_dotenvload_dotenv(override=True)sys.path.insert(0, str(Path(__file__).parent / "src"))import streamlit as st12 unmodified linesst.set_page_config(page_title="FastAPI Codebase Q&A", page_icon="⚡",layout="wide")@st.cache_resource(show_spinner="First boot: building the search index ""(~3 min, one time only)...")def ensure_index() -> bool:"""Build the Chroma index from chunks.jsonl if it doesn't exist yet."""import chromadbclient = chromadb.PersistentClient(path="data/chroma")try:if client.get_collection("chunks").count() > 0:return Trueexcept Exception:passimport index # src/index.pyindex.main()return Trueensure_index()st.title("⚡ FastAPI Codebase Q&A")st.caption("Retrieval-augmented answers over FastAPI's source code, docs, ""and GitHub issues — every claim cited, honest refusals when "17 unmodified lines"recall@5 **0.91** · MRR **0.71**\n\n""faithful **0.89** · correct **0.91** · refusal **7/7**")st.markdown("[Source & write-up]""(https://github.com/Pace200413/codebase-rag)")@st.cache_data(show_spinner=False)
app.py+29-7