nomadicsynth commited on
Commit
3a2f25f
·
1 Parent(s): 9719dbf

Add error handling for find_synergistic_papers in format_search_results_json and format_search_results functions

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -462,8 +462,11 @@ def find_synergistic_papers(abstract: str, limit=25) -> list[dict]:
462
 
463
  def format_search_results_json(abstract: str) -> str:
464
  """Format search results as JSON for display"""
465
- papers = find_synergistic_papers(abstract, limit=10)
466
- json_output = json.dumps(papers, indent=2)
 
 
 
467
 
468
  return json_output
469
 
@@ -472,7 +475,14 @@ def format_search_results(abstract: str) -> tuple[pd.DataFrame, list[dict]]:
472
  """Format search results as a DataFrame for display"""
473
  # Find papers synergistic with the given abstract
474
  # papers = embedding_model.find_synergistic_papers(abstract)
475
- papers = find_synergistic_papers(abstract)
 
 
 
 
 
 
 
476
 
477
  # Convert to DataFrame for display
478
  df = pd.DataFrame(
 
462
 
463
  def format_search_results_json(abstract: str) -> str:
464
  """Format search results as JSON for display"""
465
+ try:
466
+ papers = find_synergistic_papers(abstract, limit=10)
467
+ json_output = json.dumps(papers, indent=2)
468
+ except ValueError as e:
469
+ json_output = json.dumps({"error": str(e)}, indent=2)
470
 
471
  return json_output
472
 
 
475
  """Format search results as a DataFrame for display"""
476
  # Find papers synergistic with the given abstract
477
  # papers = embedding_model.find_synergistic_papers(abstract)
478
+ try:
479
+ papers = find_synergistic_papers(abstract)
480
+ except ValueError as e:
481
+ error_message = str(e)
482
+ df = pd.DataFrame(
483
+ [{"Title": error_message, "Authors": "", "Categories": "", "Date": "", "Match Score": ""}]
484
+ )
485
+ return df, []
486
 
487
  # Convert to DataFrame for display
488
  df = pd.DataFrame(