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

Update repo_explorer.py

Browse files
Files changed (1) hide show
  1. repo_explorer.py +15 -1
repo_explorer.py CHANGED
@@ -50,7 +50,7 @@ def create_repo_explorer_tab() -> Tuple[Dict[str, gr.components.Component], Dict
50
  "https://huggingface.co/datasets/huggingface/brand-assets/resolve/main/hf-logo.png"
51
  ),
52
  show_copy_button=True,
53
- value=[{"role": "assistant", "content": "👋 Welcome to the Repository Explorer! \n\n🔍 **How to get started:**\n1. Enter a Hugging Face repository ID above (e.g., 'microsoft/DialoGPT-medium')\n2. Click '🚀 Load Repository' to download and analyze the repository\n3. Once loaded, I'll have comprehensive knowledge of all the files and can answer questions about:\n • What the repository does\n • How to install and use it\n • Code structure and architecture\n • Key features and capabilities\n • Examples and usage patterns\n\n💡 **Tip:** I analyze repositories in chunks to understand the entire codebase, not just a summary!\n\nPlease load a repository to begin exploring! 🚀"}]
54
  )
55
 
56
  with gr.Row():
@@ -150,6 +150,16 @@ Answer the user's question based on your comprehensive knowledge of this reposit
150
 
151
  return history
152
 
 
 
 
 
 
 
 
 
 
 
153
  def setup_repo_explorer_events(components: Dict[str, gr.components.Component], states: Dict[str, gr.State]):
154
  """Setup event handlers for the repo explorer components."""
155
 
@@ -162,6 +172,10 @@ def setup_repo_explorer_events(components: Dict[str, gr.components.Component], s
162
  fn=lambda repo_id: repo_id,
163
  inputs=[components["repo_explorer_input"]],
164
  outputs=[states["current_repo_id"]]
 
 
 
 
165
  )
166
 
167
  # Chat message submission events
 
50
  "https://huggingface.co/datasets/huggingface/brand-assets/resolve/main/hf-logo.png"
51
  ),
52
  show_copy_button=True,
53
+ value=[] # Start empty - welcome message will appear only after repo is loaded
54
  )
55
 
56
  with gr.Row():
 
150
 
151
  return history
152
 
153
+ def initialize_repo_chatbot(repo_status: str, repo_id: str, repo_context_summary: str) -> List[Dict[str, str]]:
154
+ """Initialize the repository chatbot with a welcome message after successful repo loading."""
155
+ # Only initialize if repository was loaded successfully
156
+ if repo_context_summary.strip() and "successfully" in repo_status.lower():
157
+ welcome_msg = f"👋 Welcome! I've successfully analyzed the **{repo_id}** repository.\n\n🧠 **I now have comprehensive knowledge of:**\n• All files and code structure\n• Key features and capabilities\n• Installation and usage instructions\n• Architecture and implementation details\n• Dependencies and requirements\n\n💬 **Ask me anything about this repository!** \nFor example:\n• \"What does this repository do?\"\n• \"How do I install and use it?\"\n• \"What are the main components?\"\n• \"Show me usage examples\"\n\nWhat would you like to know? 🤔"
158
+ return [{"role": "assistant", "content": welcome_msg}]
159
+ else:
160
+ # Keep chatbot empty if loading failed
161
+ return []
162
+
163
  def setup_repo_explorer_events(components: Dict[str, gr.components.Component], states: Dict[str, gr.State]):
164
  """Setup event handlers for the repo explorer components."""
165
 
 
172
  fn=lambda repo_id: repo_id,
173
  inputs=[components["repo_explorer_input"]],
174
  outputs=[states["current_repo_id"]]
175
+ ).then(
176
+ fn=initialize_repo_chatbot,
177
+ inputs=[components["repo_status_display"], states["current_repo_id"], states["repo_context_summary"]],
178
+ outputs=[components["repo_chatbot"]]
179
  )
180
 
181
  # Chat message submission events