nomadicsynth commited on
Commit
d5b5c7a
·
1 Parent(s): 8d1f6b1

Normalize abstract input in find_synergistic_papers to improve cosine similarity calculations and handle empty inputs.

Browse files
Files changed (1) hide show
  1. app.py +10 -0
app.py CHANGED
@@ -428,6 +428,16 @@ def find_synergistic_papers(abstract: str, limit=25) -> list[dict]:
428
  """Find papers synergistic with the given abstract using FAISS with cosine similarity"""
429
  global dataset
430
 
 
 
 
 
 
 
 
 
 
 
431
  # Generate embedding for the query abstract (normalized for cosine similarity)
432
  abstract_embedding = embed_text(abstract)
433
 
 
428
  """Find papers synergistic with the given abstract using FAISS with cosine similarity"""
429
  global dataset
430
 
431
+ # Normalize the abstract for cosine similarity
432
+ abstract = abstract.replace("\n", " ")
433
+ # Replace multiple whitespaces with a single space
434
+ abstract = " ".join(abstract.split())
435
+ # Remove leading/trailing whitespace
436
+ abstract = abstract.strip()
437
+ # Check if the abstract is empty
438
+ if not abstract:
439
+ raise ValueError("Abstract is empty. Please provide a valid abstract.")
440
+
441
  # Generate embedding for the query abstract (normalized for cosine similarity)
442
  abstract_embedding = embed_text(abstract)
443