aman1762 commited on
Commit
4176370
·
verified ·
1 Parent(s): db5635e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -16
app.py CHANGED
@@ -8,33 +8,38 @@ st.set_page_config(page_title="Codebase RAG Assistant")
8
 
9
  st.title("🧠 Codebase RAG Assistant")
10
 
 
11
  if "qa_chain" not in st.session_state:
12
  st.session_state.qa_chain = None
13
 
 
14
  repo_url = st.text_input("GitHub Repository URL")
15
 
16
  if st.button("Index Repository"):
17
- with st.spinner("Indexing repository..."):
18
- path = load_repo(repo_url)
19
- docs = ingest_repo(path)
20
- vectorstore = create_vectorstore(docs)
21
- st.session_state.qa_chain = build_rag_chain(
22
- vectorstore,
23
- os.getenv("GROQ_API_KEY")
24
- )
25
- st.success("Repository indexed successfully!")
26
-
 
 
 
 
27
  question = st.text_input("Ask a question about the codebase")
28
 
29
  if st.button("Ask"):
30
  if st.session_state.qa_chain is None:
31
  st.warning("Please index a repository first")
 
 
32
  else:
33
  with st.spinner("Thinking..."):
34
- result = st.session_state.qa_chain.invoke(question)
35
 
36
- st.markdown("### Answer")
37
- st.write(answer)
38
- st.markdown("### Sources")
39
- for doc in result["source_documents"]:
40
- st.write(doc.metadata["file"])
 
8
 
9
  st.title("🧠 Codebase RAG Assistant")
10
 
11
+ # Session state
12
  if "qa_chain" not in st.session_state:
13
  st.session_state.qa_chain = None
14
 
15
+ # Input: GitHub repo
16
  repo_url = st.text_input("GitHub Repository URL")
17
 
18
  if st.button("Index Repository"):
19
+ if not repo_url:
20
+ st.warning("Please enter a GitHub repository URL")
21
+ else:
22
+ with st.spinner("Indexing repository..."):
23
+ path = load_repo(repo_url)
24
+ docs = ingest_repo(path)
25
+ vectorstore = create_vectorstore(docs)
26
+ st.session_state.qa_chain = build_rag_chain(
27
+ vectorstore,
28
+ os.getenv("GROQ_API_KEY")
29
+ )
30
+ st.success("Repository indexed successfully!")
31
+
32
+ # Input: question
33
  question = st.text_input("Ask a question about the codebase")
34
 
35
  if st.button("Ask"):
36
  if st.session_state.qa_chain is None:
37
  st.warning("Please index a repository first")
38
+ elif not question:
39
+ st.warning("Please enter a question")
40
  else:
41
  with st.spinner("Thinking..."):
42
+ answer = st.session_state.qa_chain.invoke(question)
43
 
44
+ st.markdown("### Answer")
45
+ st.write(answer)