Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion gradio/external_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ def zero_shot_classification_inner(input: str, labels: str, multi_label: bool):

def sentence_similarity_wrapper(client: InferenceClient):
def sentence_similarity_inner(input: str, sentences: str):
return client.sentence_similarity(input, sentences.split("\n"))
# Avoid unnecessary work if 'sentences' is empty:
if not sentences:
return client.sentence_similarity(input, [])
# Using splitlines is usually faster than split("\n"), and avoids trailing empty strings for trailing newlines
sentence_list = sentences.splitlines()
return client.sentence_similarity(input, sentence_list)

return sentence_similarity_inner

Expand Down