Update repo_explorer.py
Browse files- repo_explorer.py +33 -18
repo_explorer.py
CHANGED
@@ -154,7 +154,13 @@ 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 |
|
159 |
with gr.Row():
|
160 |
repo_status_display = gr.Textbox(
|
@@ -202,7 +208,7 @@ def create_repo_explorer_tab() -> Tuple[Dict[str, gr.components.Component], Dict
|
|
202 |
components = {
|
203 |
"repo_explorer_input": repo_explorer_input,
|
204 |
"load_repo_btn": load_repo_btn,
|
205 |
-
"
|
206 |
"repo_status_display": repo_status_display,
|
207 |
"repo_chatbot": repo_chatbot,
|
208 |
"repo_msg_input": repo_msg_input,
|
@@ -298,10 +304,27 @@ def get_huggingface_url(repo_id: str) -> str:
|
|
298 |
return ""
|
299 |
return f"https://huggingface.co/spaces/{repo_id}"
|
300 |
|
301 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.", "",
|
305 |
|
306 |
try:
|
307 |
logger.info(f"Loading repository with vectorization: {repo_id}")
|
@@ -313,7 +336,7 @@ def handle_load_repository_with_vectorization(repo_id: str) -> Tuple[str, str, g
|
|
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, "",
|
317 |
|
318 |
# Read the combined content
|
319 |
with open(combined_text_path, "r", encoding="utf-8") as f:
|
@@ -332,16 +355,16 @@ def handle_load_repository_with_vectorization(repo_id: str) -> Tuple[str, str, g
|
|
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 |
-
#
|
336 |
-
|
337 |
|
338 |
logger.info(f"Repository {repo_id} loaded and processed successfully")
|
339 |
-
return status, context_summary,
|
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, "",
|
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,7 +386,7 @@ def setup_repo_explorer_events(components: Dict[str, gr.components.Component], s
|
|
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["
|
367 |
).then(
|
368 |
fn=lambda repo_id: repo_id,
|
369 |
inputs=[components["repo_explorer_input"]],
|
@@ -374,14 +397,6 @@ def setup_repo_explorer_events(components: Dict[str, gr.components.Component], s
|
|
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/spaces/' + repo_id, '_blank'); }"
|
383 |
-
)
|
384 |
-
|
385 |
# Chat message submission events
|
386 |
components["repo_msg_input"].submit(
|
387 |
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 |
+
|
158 |
+
with gr.Row():
|
159 |
+
visit_hf_link = gr.HTML(
|
160 |
+
value="",
|
161 |
+
label="π Repository Link",
|
162 |
+
visible=False
|
163 |
+
)
|
164 |
|
165 |
with gr.Row():
|
166 |
repo_status_display = gr.Textbox(
|
|
|
208 |
components = {
|
209 |
"repo_explorer_input": repo_explorer_input,
|
210 |
"load_repo_btn": load_repo_btn,
|
211 |
+
"visit_hf_link": visit_hf_link,
|
212 |
"repo_status_display": repo_status_display,
|
213 |
"repo_chatbot": repo_chatbot,
|
214 |
"repo_msg_input": repo_msg_input,
|
|
|
304 |
return ""
|
305 |
return f"https://huggingface.co/spaces/{repo_id}"
|
306 |
|
307 |
+
def generate_repo_link_html(repo_id: str) -> str:
|
308 |
+
"""Generate HTML with clickable link for the repository."""
|
309 |
+
if not repo_id or not repo_id.strip():
|
310 |
+
return ""
|
311 |
+
|
312 |
+
clean_repo_id = str(repo_id).strip()
|
313 |
+
hf_url = f"https://huggingface.co/spaces/{clean_repo_id}"
|
314 |
+
|
315 |
+
html_link = f'''
|
316 |
+
<div style="margin: 10px 0; padding: 15px; background: rgba(255, 255, 255, 0.1); border-radius: 12px; backdrop-filter: blur(10px); text-align: center;">
|
317 |
+
<a href="{hf_url}" target="_blank" style="display: inline-block; padding: 12px 24px; background: linear-gradient(45deg, #667eea, #764ba2); color: white; text-decoration: none; border-radius: 8px; font-weight: 600; font-size: 16px; transition: all 0.3s ease; box-shadow: 0 4px 12px rgba(0,0,0,0.2);">
|
318 |
+
π Visit {clean_repo_id} on Hugging Face
|
319 |
+
</a>
|
320 |
+
</div>
|
321 |
+
'''
|
322 |
+
return html_link
|
323 |
+
|
324 |
+
def handle_load_repository_with_vectorization(repo_id: str) -> Tuple[str, str, str]:
|
325 |
"""Load repository and create both context summary and vector embeddings."""
|
326 |
if not repo_id.strip():
|
327 |
+
return "Status: Please enter a repository ID.", "", ""
|
328 |
|
329 |
try:
|
330 |
logger.info(f"Loading repository with vectorization: {repo_id}")
|
|
|
336 |
except Exception as e:
|
337 |
logger.error(f"Error downloading repository {repo_id}: {e}")
|
338 |
error_status = f"β Error downloading repository: {e}"
|
339 |
+
return error_status, "", ""
|
340 |
|
341 |
# Read the combined content
|
342 |
with open(combined_text_path, "r", encoding="utf-8") as f:
|
|
|
355 |
else:
|
356 |
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."
|
357 |
|
358 |
+
# Generate the HTML link for the repository
|
359 |
+
repo_link_html = generate_repo_link_html(repo_id)
|
360 |
|
361 |
logger.info(f"Repository {repo_id} loaded and processed successfully")
|
362 |
+
return status, context_summary, repo_link_html
|
363 |
|
364 |
except Exception as e:
|
365 |
logger.error(f"Error loading repository {repo_id}: {e}")
|
366 |
error_status = f"β Error loading repository: {e}"
|
367 |
+
return error_status, "", ""
|
368 |
|
369 |
def initialize_repo_chatbot(repo_status: str, repo_id: str, repo_context_summary: str) -> List[Dict[str, str]]:
|
370 |
"""Initialize the repository chatbot with a welcome message after successful repo loading."""
|
|
|
386 |
components["load_repo_btn"].click(
|
387 |
fn=handle_load_repository_with_vectorization,
|
388 |
inputs=[components["repo_explorer_input"]],
|
389 |
+
outputs=[components["repo_status_display"], states["repo_context_summary"], components["visit_hf_link"]]
|
390 |
).then(
|
391 |
fn=lambda repo_id: repo_id,
|
392 |
inputs=[components["repo_explorer_input"]],
|
|
|
397 |
outputs=[components["repo_chatbot"]]
|
398 |
)
|
399 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
400 |
# Chat message submission events
|
401 |
components["repo_msg_input"].submit(
|
402 |
fn=handle_repo_user_message,
|