Your Name commited on
Commit
f3e970d
Β·
1 Parent(s): a3f4dff

made changes in side bar

Browse files
Files changed (1) hide show
  1. app.py +29 -22
app.py CHANGED
@@ -204,27 +204,28 @@ st.markdown(
204
  )
205
  st.divider()
206
 
207
- # ── Sidebar ───────────────────────────────────────────────
208
  with st.sidebar:
209
  st.header("πŸ“¦ Load Repository")
210
 
211
- github_url = st.text_input(
 
 
 
 
 
 
 
 
 
 
 
 
212
  "GitHub Repository URL",
 
213
  placeholder="https://github.com/username/repo"
214
  )
215
 
216
- st.markdown("**Try these:**")
217
- if st.button("πŸ“ Spoon-Knife (small)", use_container_width=True):
218
- st.session_state["prefill_url"] = "https://github.com/octocat/Spoon-Knife"
219
- st.rerun()
220
-
221
- if st.button("πŸ“ Flask (medium)", use_container_width=True):
222
- st.session_state["prefill_url"] = "https://github.com/pallets/flask"
223
- st.rerun()
224
-
225
- if "prefill_url" in st.session_state:
226
- github_url = st.session_state.pop("prefill_url")
227
-
228
  if github_url:
229
  if st.button(
230
  "πŸš€ Load & Index",
@@ -232,19 +233,20 @@ with st.sidebar:
232
  type="primary"
233
  ):
234
  try:
235
- # Reset
236
- st.session_state.messages = []
237
- st.session_state.history = ChatMessageHistory()
238
- st.session_state.indexed = False
239
 
240
- with st.spinner("Cloning repository..."):
241
  clone_path, repo_name = clone_repo(github_url)
242
 
243
- with st.spinner("Loading and indexing files..."):
244
  all_docs = load_code_files(clone_path)
245
  if not all_docs:
246
  st.error("No readable files found!")
247
  st.stop()
 
 
248
  vectorstore, n_files, n_chunks = split_and_index(all_docs)
249
 
250
  st.session_state.vectorstore = vectorstore
@@ -254,14 +256,17 @@ with st.sidebar:
254
  "files" : n_files,
255
  "chunks": n_chunks
256
  }
257
- st.success(f"βœ… Ready!")
 
 
 
258
 
259
  except Exception as e:
260
  st.error(f"Error: {str(e)}")
261
 
262
  if st.session_state.indexed:
263
  st.divider()
264
- st.metric("Files", st.session_state.stats["files"])
265
  st.metric("Chunks", st.session_state.stats["chunks"])
266
  st.markdown(f"**Repo:** {st.session_state.repo_name}")
267
 
@@ -270,6 +275,8 @@ with st.sidebar:
270
  st.session_state.indexed = False
271
  st.session_state.messages = []
272
  st.session_state.history = ChatMessageHistory()
 
 
273
  st.rerun()
274
 
275
  # ── Main area ─────────────────────────────────────────────
 
204
  )
205
  st.divider()
206
 
 
207
  with st.sidebar:
208
  st.header("πŸ“¦ Load Repository")
209
 
210
+ # ── Quick fill buttons ────────────────────────────────
211
+ st.markdown("**Try these:**")
212
+ col1, col2 = st.columns(2)
213
+ with col1:
214
+ if st.button("πŸ“ Spoon-Knife", use_container_width=True):
215
+ st.session_state["prefill_url"] = "https://github.com/octocat/Spoon-Knife"
216
+ with col2:
217
+ if st.button("πŸ“ Flask", use_container_width=True):
218
+ st.session_state["prefill_url"] = "https://github.com/pallets/flask"
219
+
220
+ # ── URL input ─────────────────────────────────────────
221
+ default_url = st.session_state.get("prefill_url", "")
222
+ github_url = st.text_input(
223
  "GitHub Repository URL",
224
+ value=default_url,
225
  placeholder="https://github.com/username/repo"
226
  )
227
 
228
+ # ── Load button ───────────────────────────────────────
 
 
 
 
 
 
 
 
 
 
 
229
  if github_url:
230
  if st.button(
231
  "πŸš€ Load & Index",
 
233
  type="primary"
234
  ):
235
  try:
236
+ st.session_state.messages = []
237
+ st.session_state.history = ChatMessageHistory()
238
+ st.session_state.indexed = False
 
239
 
240
+ with st.spinner("Step 1/3: Cloning repository..."):
241
  clone_path, repo_name = clone_repo(github_url)
242
 
243
+ with st.spinner("Step 2/3: Loading files..."):
244
  all_docs = load_code_files(clone_path)
245
  if not all_docs:
246
  st.error("No readable files found!")
247
  st.stop()
248
+
249
+ with st.spinner(f"Step 3/3: Indexing {len(all_docs)} files..."):
250
  vectorstore, n_files, n_chunks = split_and_index(all_docs)
251
 
252
  st.session_state.vectorstore = vectorstore
 
256
  "files" : n_files,
257
  "chunks": n_chunks
258
  }
259
+ # Clear prefill after successful load
260
+ if "prefill_url" in st.session_state:
261
+ del st.session_state["prefill_url"]
262
+ st.success("βœ… Ready!")
263
 
264
  except Exception as e:
265
  st.error(f"Error: {str(e)}")
266
 
267
  if st.session_state.indexed:
268
  st.divider()
269
+ st.metric("Files", st.session_state.stats["files"])
270
  st.metric("Chunks", st.session_state.stats["chunks"])
271
  st.markdown(f"**Repo:** {st.session_state.repo_name}")
272
 
 
275
  st.session_state.indexed = False
276
  st.session_state.messages = []
277
  st.session_state.history = ChatMessageHistory()
278
+ if "prefill_url" in st.session_state:
279
+ del st.session_state["prefill_url"]
280
  st.rerun()
281
 
282
  # ── Main area ─────────────────────────────────────────────