aman1762 commited on
Commit
f812374
·
verified ·
1 Parent(s): 7b50cfc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -22
app.py CHANGED
@@ -1,35 +1,42 @@
1
-
 
2
  import time
 
 
3
  time.sleep(3)
4
 
5
- import streamlit as st
6
- import requests
7
 
8
  st.title("🧠 Codebase RAG Assistant")
9
 
10
  repo_url = st.text_input("GitHub Repository URL")
11
 
12
  if st.button("Index Repository"):
13
- res = requests.post(
14
- f"{BACKEND_URL}/load",
15
- params={"repo_url": repo_url}
16
- )
17
-
18
- st.success("Repository indexed!")
 
 
19
 
20
  question = st.text_input("Ask a question about the codebase")
21
 
22
  if st.button("Ask"):
23
- BACKEND_URL = "http://127.0.0.1:8000"
24
-
25
- res = requests.get(
26
- f"{BACKEND_URL}/ask",
27
- params={"question": question}
28
- ).json()
29
-
30
- st.write("### Answer")
31
- st.write(res["answer"])
32
-
33
- st.write("### Sources")
34
- for src in res["sources"]:
35
- st.write(src)
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
  import time
4
+
5
+ # Wait for FastAPI backend to start
6
  time.sleep(3)
7
 
8
+ BACKEND_URL = "http://127.0.0.1:8000"
 
9
 
10
  st.title("🧠 Codebase RAG Assistant")
11
 
12
  repo_url = st.text_input("GitHub Repository URL")
13
 
14
  if st.button("Index Repository"):
15
+ response = requests.post(
16
+ f"{BACKEND_URL}/load",
17
+ params={"repo_url": repo_url}
18
+ )
19
+ if response.status_code == 200:
20
+ st.success("Repository indexed successfully!")
21
+ else:
22
+ st.error("Failed to index repository")
23
 
24
  question = st.text_input("Ask a question about the codebase")
25
 
26
  if st.button("Ask"):
27
+ response = requests.get(
28
+ f"{BACKEND_URL}/ask",
29
+ params={"question": question}
30
+ )
31
+
32
+ if response.status_code == 200:
33
+ data = response.json()
34
+
35
+ st.write("### Answer")
36
+ st.write(data["answer"])
37
+
38
+ st.write("### Sources")
39
+ for src in data["sources"]:
40
+ st.write(src)
41
+ else:
42
+ st.error("Failed to get answer from backend")