Spaces:
Sleeping
Sleeping
Update repo_explorer.py
Browse files- repo_explorer.py +25 -6
repo_explorer.py
CHANGED
@@ -154,6 +154,7 @@ def create_repo_explorer_tab() -> Tuple[Dict[str, gr.components.Component], Dict
|
|
154 |
)
|
155 |
with gr.Column(scale=1):
|
156 |
load_repo_btn = gr.Button("π Load Repository", variant="primary", size="lg")
|
|
|
157 |
|
158 |
with gr.Row():
|
159 |
repo_status_display = gr.Textbox(
|
@@ -201,6 +202,7 @@ def create_repo_explorer_tab() -> Tuple[Dict[str, gr.components.Component], Dict
|
|
201 |
components = {
|
202 |
"repo_explorer_input": repo_explorer_input,
|
203 |
"load_repo_btn": load_repo_btn,
|
|
|
204 |
"repo_status_display": repo_status_display,
|
205 |
"repo_chatbot": repo_chatbot,
|
206 |
"repo_msg_input": repo_msg_input,
|
@@ -290,10 +292,16 @@ Answer the user's question based on your comprehensive knowledge of this reposit
|
|
290 |
|
291 |
return history
|
292 |
|
293 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
294 |
"""Load repository and create both context summary and vector embeddings."""
|
295 |
if not repo_id.strip():
|
296 |
-
return "Status: Please enter a repository ID.", ""
|
297 |
|
298 |
try:
|
299 |
logger.info(f"Loading repository with vectorization: {repo_id}")
|
@@ -305,7 +313,7 @@ def handle_load_repository_with_vectorization(repo_id: str) -> Tuple[str, str]:
|
|
305 |
except Exception as e:
|
306 |
logger.error(f"Error downloading repository {repo_id}: {e}")
|
307 |
error_status = f"β Error downloading repository: {e}"
|
308 |
-
return error_status, ""
|
309 |
|
310 |
# Read the combined content
|
311 |
with open(combined_text_path, "r", encoding="utf-8") as f:
|
@@ -324,13 +332,16 @@ def handle_load_repository_with_vectorization(repo_id: str) -> Tuple[str, str]:
|
|
324 |
else:
|
325 |
status = f"β
Repository '{repo_id}' loaded successfully!\nπ Files processed and ready for exploration.\nβ οΈ Vectorization failed - using text-only analysis.\nπ¬ You can now ask questions about this repository."
|
326 |
|
|
|
|
|
|
|
327 |
logger.info(f"Repository {repo_id} loaded and processed successfully")
|
328 |
-
return status, context_summary
|
329 |
|
330 |
except Exception as e:
|
331 |
logger.error(f"Error loading repository {repo_id}: {e}")
|
332 |
error_status = f"β Error loading repository: {e}"
|
333 |
-
return error_status, ""
|
334 |
|
335 |
def initialize_repo_chatbot(repo_status: str, repo_id: str, repo_context_summary: str) -> List[Dict[str, str]]:
|
336 |
"""Initialize the repository chatbot with a welcome message after successful repo loading."""
|
@@ -352,7 +363,7 @@ def setup_repo_explorer_events(components: Dict[str, gr.components.Component], s
|
|
352 |
components["load_repo_btn"].click(
|
353 |
fn=handle_load_repository_with_vectorization,
|
354 |
inputs=[components["repo_explorer_input"]],
|
355 |
-
outputs=[components["repo_status_display"], states["repo_context_summary"]]
|
356 |
).then(
|
357 |
fn=lambda repo_id: repo_id,
|
358 |
inputs=[components["repo_explorer_input"]],
|
@@ -363,6 +374,14 @@ def setup_repo_explorer_events(components: Dict[str, gr.components.Component], s
|
|
363 |
outputs=[components["repo_chatbot"]]
|
364 |
)
|
365 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
366 |
# Chat message submission events
|
367 |
components["repo_msg_input"].submit(
|
368 |
fn=handle_repo_user_message,
|
|
|
154 |
)
|
155 |
with gr.Column(scale=1):
|
156 |
load_repo_btn = gr.Button("π Load Repository", variant="primary", size="lg")
|
157 |
+
visit_hf_btn = gr.Button("π Visit on HF", variant="secondary", size="lg", visible=False)
|
158 |
|
159 |
with gr.Row():
|
160 |
repo_status_display = gr.Textbox(
|
|
|
202 |
components = {
|
203 |
"repo_explorer_input": repo_explorer_input,
|
204 |
"load_repo_btn": load_repo_btn,
|
205 |
+
"visit_hf_btn": visit_hf_btn,
|
206 |
"repo_status_display": repo_status_display,
|
207 |
"repo_chatbot": repo_chatbot,
|
208 |
"repo_msg_input": repo_msg_input,
|
|
|
292 |
|
293 |
return history
|
294 |
|
295 |
+
def get_huggingface_url(repo_id: str) -> str:
|
296 |
+
"""Generate the Hugging Face URL for a repository."""
|
297 |
+
if not repo_id.strip():
|
298 |
+
return ""
|
299 |
+
return f"https://huggingface.co/{repo_id}"
|
300 |
+
|
301 |
+
def handle_load_repository_with_vectorization(repo_id: str) -> Tuple[str, str, gr.Button]:
|
302 |
"""Load repository and create both context summary and vector embeddings."""
|
303 |
if not repo_id.strip():
|
304 |
+
return "Status: Please enter a repository ID.", "", gr.Button(visible=False)
|
305 |
|
306 |
try:
|
307 |
logger.info(f"Loading repository with vectorization: {repo_id}")
|
|
|
313 |
except Exception as e:
|
314 |
logger.error(f"Error downloading repository {repo_id}: {e}")
|
315 |
error_status = f"β Error downloading repository: {e}"
|
316 |
+
return error_status, "", gr.Button(visible=False)
|
317 |
|
318 |
# Read the combined content
|
319 |
with open(combined_text_path, "r", encoding="utf-8") as f:
|
|
|
332 |
else:
|
333 |
status = f"β
Repository '{repo_id}' loaded successfully!\nπ Files processed and ready for exploration.\nβ οΈ Vectorization failed - using text-only analysis.\nπ¬ You can now ask questions about this repository."
|
334 |
|
335 |
+
# Show the HF visit button since repository loaded successfully
|
336 |
+
updated_button = gr.Button("π Visit on HF", variant="secondary", size="lg", visible=True)
|
337 |
+
|
338 |
logger.info(f"Repository {repo_id} loaded and processed successfully")
|
339 |
+
return status, context_summary, updated_button
|
340 |
|
341 |
except Exception as e:
|
342 |
logger.error(f"Error loading repository {repo_id}: {e}")
|
343 |
error_status = f"β Error loading repository: {e}"
|
344 |
+
return error_status, "", gr.Button(visible=False)
|
345 |
|
346 |
def initialize_repo_chatbot(repo_status: str, repo_id: str, repo_context_summary: str) -> List[Dict[str, str]]:
|
347 |
"""Initialize the repository chatbot with a welcome message after successful repo loading."""
|
|
|
363 |
components["load_repo_btn"].click(
|
364 |
fn=handle_load_repository_with_vectorization,
|
365 |
inputs=[components["repo_explorer_input"]],
|
366 |
+
outputs=[components["repo_status_display"], states["repo_context_summary"], components["visit_hf_btn"]]
|
367 |
).then(
|
368 |
fn=lambda repo_id: repo_id,
|
369 |
inputs=[components["repo_explorer_input"]],
|
|
|
374 |
outputs=[components["repo_chatbot"]]
|
375 |
)
|
376 |
|
377 |
+
# Visit Hugging Face repository button - opens in new tab
|
378 |
+
components["visit_hf_btn"].click(
|
379 |
+
fn=None,
|
380 |
+
inputs=[states["current_repo_id"]],
|
381 |
+
outputs=[],
|
382 |
+
js="(repo_id) => { if(repo_id) window.open('https://huggingface.co/' + repo_id, '_blank'); }"
|
383 |
+
)
|
384 |
+
|
385 |
# Chat message submission events
|
386 |
components["repo_msg_input"].submit(
|
387 |
fn=handle_repo_user_message,
|