Update app.py
Browse files
app.py
CHANGED
@@ -400,8 +400,39 @@ def create_ui() -> gr.Blocks:
|
|
400 |
|
401 |
def keyword_search_with_status(keyword: str, state: AppState) -> Tuple[pd.DataFrame, str]:
|
402 |
"""Search keywords with status update."""
|
403 |
-
|
404 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
405 |
|
406 |
def analyze_with_status(state: AppState) -> Tuple[str, str, pd.DataFrame, str]:
|
407 |
"""Analyze with status update."""
|
@@ -441,12 +472,20 @@ def create_ui() -> gr.Blocks:
|
|
441 |
outputs=[df_output, submit_status]
|
442 |
)
|
443 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
444 |
search_btn.click(
|
445 |
-
fn=
|
446 |
inputs=[],
|
447 |
outputs=[search_status]
|
448 |
).then(
|
449 |
-
fn=
|
450 |
inputs=[keyword_input, state],
|
451 |
outputs=[df_output, search_status]
|
452 |
)
|
|
|
400 |
|
401 |
def keyword_search_with_status(keyword: str, state: AppState) -> Tuple[pd.DataFrame, str]:
|
402 |
"""Search keywords with status update."""
|
403 |
+
try:
|
404 |
+
if not keyword:
|
405 |
+
return pd.DataFrame(columns=["repo id", "strength", "weaknesses", "speciality", "relevance rating"]), ""
|
406 |
+
|
407 |
+
keyword_list = [k.strip() for k in re.split(r'[\n,]+', keyword) if k.strip()]
|
408 |
+
repo_ids = []
|
409 |
+
|
410 |
+
for kw in keyword_list:
|
411 |
+
try:
|
412 |
+
results = search_top_spaces(kw, limit=5)
|
413 |
+
repo_ids.extend(results)
|
414 |
+
except Exception as e:
|
415 |
+
logger.error(f"Error searching for keyword {kw}: {e}")
|
416 |
+
continue
|
417 |
+
|
418 |
+
# Remove duplicates while preserving order
|
419 |
+
seen = set()
|
420 |
+
unique_repo_ids = []
|
421 |
+
for rid in repo_ids:
|
422 |
+
if rid not in seen:
|
423 |
+
unique_repo_ids.append(rid)
|
424 |
+
seen.add(rid)
|
425 |
+
|
426 |
+
state.repo_ids = unique_repo_ids
|
427 |
+
state.current_repo_idx = 0
|
428 |
+
|
429 |
+
write_repos_to_csv(unique_repo_ids)
|
430 |
+
df = read_csv_as_text("repo_ids.csv")
|
431 |
+
return df, ""
|
432 |
+
|
433 |
+
except Exception as e:
|
434 |
+
logger.error(f"Error in keyword search: {e}")
|
435 |
+
return pd.DataFrame(columns=["repo id", "strength", "weaknesses", "speciality", "relevance rating"]), f"Error: {str(e)}"
|
436 |
|
437 |
def analyze_with_status(state: AppState) -> Tuple[str, str, pd.DataFrame, str]:
|
438 |
"""Analyze with status update."""
|
|
|
472 |
outputs=[df_output, submit_status]
|
473 |
)
|
474 |
|
475 |
+
def search_click():
|
476 |
+
"""Handle search button click."""
|
477 |
+
return "Searching..."
|
478 |
+
|
479 |
+
def search_complete(keyword: str, state: AppState):
|
480 |
+
"""Complete search operation."""
|
481 |
+
return keyword_search_with_status(keyword, state)
|
482 |
+
|
483 |
search_btn.click(
|
484 |
+
fn=search_click,
|
485 |
inputs=[],
|
486 |
outputs=[search_status]
|
487 |
).then(
|
488 |
+
fn=search_complete,
|
489 |
inputs=[keyword_input, state],
|
490 |
outputs=[df_output, search_status]
|
491 |
)
|