naman1102 commited on
Commit
4f3470b
·
1 Parent(s): da66b3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -6
app.py CHANGED
@@ -16,7 +16,7 @@ from analyzer import (
16
  )
17
  from hf_utils import download_filtered_space_files, search_top_spaces
18
  from chatbot_page import chat_with_user, extract_keywords_from_conversation
19
- from repo_explorer import create_repo_explorer_tab, setup_repo_explorer_events
20
 
21
  # --- Configuration ---
22
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@@ -918,8 +918,8 @@ def create_ui() -> gr.Blocks:
918
  return gr.update(visible=False), hf_url
919
  return gr.update(visible=False), ""
920
 
921
- def handle_explore_repo(selected_repo_id: str) -> Tuple[Any, Any, Any]:
922
- """Handle navigating to the repo explorer and populate the repo ID."""
923
  logger.info(f"DEBUG: handle_explore_repo called with selected_repo_id: '{selected_repo_id}'")
924
 
925
  if selected_repo_id and selected_repo_id.strip() and selected_repo_id.strip() != 'nan':
@@ -927,13 +927,17 @@ def create_ui() -> gr.Blocks:
927
  return (
928
  gr.update(visible=False), # close modal
929
  gr.update(selected="repo_explorer_tab"), # switch tab
930
- gr.update(value=clean_repo_id) # populate repo explorer input
 
 
931
  )
932
  else:
933
  return (
934
  gr.update(visible=False), # close modal
935
  gr.update(selected="repo_explorer_tab"), # switch tab
936
- gr.update() # don't change repo explorer input
 
 
937
  )
938
 
939
  def handle_cancel_modal() -> Any:
@@ -1335,7 +1339,9 @@ def create_ui() -> gr.Blocks:
1335
  outputs=[
1336
  repo_action_modal,
1337
  tabs,
1338
- repo_components["repo_explorer_input"]
 
 
1339
  ],
1340
  js="""(repo_id) => {
1341
  console.log('DEBUG: Navigate to repo explorer for:', repo_id);
@@ -1343,6 +1349,19 @@ def create_ui() -> gr.Blocks:
1343
  window.scrollTo({top: 0, behavior: 'smooth'});
1344
  }, 200);
1345
  }"""
 
 
 
 
 
 
 
 
 
 
 
 
 
1346
  )
1347
  cancel_modal_btn.click(
1348
  fn=handle_cancel_modal,
 
16
  )
17
  from hf_utils import download_filtered_space_files, search_top_spaces
18
  from chatbot_page import chat_with_user, extract_keywords_from_conversation
19
+ from repo_explorer import create_repo_explorer_tab, setup_repo_explorer_events, initialize_repo_chatbot
20
 
21
  # --- Configuration ---
22
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
 
918
  return gr.update(visible=False), hf_url
919
  return gr.update(visible=False), ""
920
 
921
+ def handle_explore_repo(selected_repo_id: str) -> Tuple[Any, Any, Any, str, str]:
922
+ """Handle navigating to the repo explorer and automatically load the repository."""
923
  logger.info(f"DEBUG: handle_explore_repo called with selected_repo_id: '{selected_repo_id}'")
924
 
925
  if selected_repo_id and selected_repo_id.strip() and selected_repo_id.strip() != 'nan':
 
927
  return (
928
  gr.update(visible=False), # close modal
929
  gr.update(selected="repo_explorer_tab"), # switch tab
930
+ gr.update(value=clean_repo_id), # populate repo explorer input
931
+ clean_repo_id, # trigger repository loading with the repo ID
932
+ "auto_load" # signal to auto-load the repository
933
  )
934
  else:
935
  return (
936
  gr.update(visible=False), # close modal
937
  gr.update(selected="repo_explorer_tab"), # switch tab
938
+ gr.update(), # don't change repo explorer input
939
+ "", # no repo ID to load
940
+ "" # no auto-load signal
941
  )
942
 
943
  def handle_cancel_modal() -> Any:
 
1339
  outputs=[
1340
  repo_action_modal,
1341
  tabs,
1342
+ repo_components["repo_explorer_input"],
1343
+ repo_states["current_repo_id"], # Set the current repo ID
1344
+ status_box_input # Use for auto-load signal
1345
  ],
1346
  js="""(repo_id) => {
1347
  console.log('DEBUG: Navigate to repo explorer for:', repo_id);
 
1349
  window.scrollTo({top: 0, behavior: 'smooth'});
1350
  }, 200);
1351
  }"""
1352
+ ).then(
1353
+ # Auto-load the repository if the signal indicates to do so
1354
+ fn=lambda repo_id, signal: handle_load_repository(repo_id) if signal == "auto_load" and repo_id else ("", ""),
1355
+ inputs=[repo_states["current_repo_id"], status_box_input],
1356
+ outputs=[repo_components["repo_status_display"], repo_states["repo_context_summary"]]
1357
+ ).then(
1358
+ # Initialize the chatbot with welcome message after auto-loading
1359
+ fn=lambda repo_status, repo_id, repo_context, signal: (
1360
+ initialize_repo_chatbot(repo_status, repo_id, repo_context)
1361
+ if signal == "auto_load" and repo_id else []
1362
+ ),
1363
+ inputs=[repo_components["repo_status_display"], repo_states["current_repo_id"], repo_states["repo_context_summary"], status_box_input],
1364
+ outputs=[repo_components["repo_chatbot"]]
1365
  )
1366
  cancel_modal_btn.click(
1367
  fn=handle_cancel_modal,