aman1762 commited on
Commit
7dd0ba0
·
verified ·
1 Parent(s): 21a69f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -16
app.py CHANGED
@@ -1,43 +1,65 @@
1
  import streamlit as st
2
  import os
3
 
4
- from ingest import load_repo, ingest_repo
5
  from vectorstore import create_vectorstore
6
  from rag_chain import build_rag_chain
7
 
8
  st.set_page_config(page_title="Codebase RAG Assistant")
9
-
10
  st.title("🧠 Codebase RAG Assistant")
11
 
12
- # Session state
13
  if "qa_chain" not in st.session_state:
14
  st.session_state.qa_chain = None
15
 
16
- # Input repo URL
17
- repo_url = st.text_input("GitHub Repository URL")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
- if st.button("Index Repository"):
20
- if not repo_url:
21
- st.warning("Please enter a GitHub repository URL")
22
- else:
23
- with st.spinner("Cloning and indexing repository..."):
24
- repo_path = load_repo(repo_url)
25
- docs = ingest_repo(repo_path)
26
  vectorstore = create_vectorstore(docs)
27
  st.session_state.qa_chain = build_rag_chain(
28
  vectorstore,
29
  os.getenv("GROQ_API_KEY")
30
  )
31
- st.success("Repository indexed successfully!")
32
 
33
- # Question input
 
 
 
 
34
  question = st.text_input("Ask a question about the codebase")
35
 
36
  if st.button("Ask"):
37
  if st.session_state.qa_chain is None:
38
- st.warning("Please index a repository first")
39
  elif not question.strip():
40
- st.warning("Please enter a question")
41
  else:
42
  with st.spinner("Thinking..."):
43
  answer = st.session_state.qa_chain.invoke(question)
 
1
  import streamlit as st
2
  import os
3
 
4
+ from ingest import load_repo, ingest_repo, extract_zip
5
  from vectorstore import create_vectorstore
6
  from rag_chain import build_rag_chain
7
 
8
  st.set_page_config(page_title="Codebase RAG Assistant")
 
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
+ st.subheader("Input Source")
15
+
16
+ repo_url = st.text_input("GitHub Repository URL (optional)")
17
+ uploaded_zip = st.file_uploader("Or upload ZIP file", type=["zip"])
18
+
19
+ if st.button("Index Codebase"):
20
+ try:
21
+ with st.spinner("Processing codebase..."):
22
+
23
+ if uploaded_zip:
24
+ repo_path = extract_zip(uploaded_zip)
25
+ docs = ingest_repo(repo_path)
26
+
27
+ elif repo_url:
28
+ if "/blob/" in repo_url:
29
+ st.error("Please provide a repository URL, not a file URL.")
30
+ st.stop()
31
+ repo_path = load_repo(repo_url)
32
+ docs = ingest_repo(repo_path)
33
+
34
+ else:
35
+ st.warning("Provide GitHub repo URL or upload ZIP.")
36
+ st.stop()
37
+
38
+ if not docs:
39
+ st.error(
40
+ "No supported source files found.\n\n"
41
+ "Supported: .py, .js, .java, .cpp, .txt, .ipynb"
42
+ )
43
+ st.stop()
44
 
 
 
 
 
 
 
 
45
  vectorstore = create_vectorstore(docs)
46
  st.session_state.qa_chain = build_rag_chain(
47
  vectorstore,
48
  os.getenv("GROQ_API_KEY")
49
  )
 
50
 
51
+ st.success("Indexing completed!")
52
+
53
+ except Exception as e:
54
+ st.error(str(e))
55
+
56
  question = st.text_input("Ask a question about the codebase")
57
 
58
  if st.button("Ask"):
59
  if st.session_state.qa_chain is None:
60
+ st.warning("Index a codebase first.")
61
  elif not question.strip():
62
+ st.warning("Enter a question.")
63
  else:
64
  with st.spinner("Thinking..."):
65
  answer = st.session_state.qa_chain.invoke(question)