|
import gradio as gr |
|
from sentence_transformers import SentenceTransformer, util |
|
|
|
|
|
model = SentenceTransformer('sartifyllc/AviLaBSE') |
|
|
|
|
|
def compute_similarities(original_sentence, sentences_to_compare): |
|
|
|
embeddings_original = model.encode([original_sentence]) |
|
embeddings_sentences_to_compare = model.encode(sentences_to_compare) |
|
|
|
|
|
similarities = util.cos_sim(embeddings_original, embeddings_sentences_to_compare) |
|
|
|
|
|
results = [(sentence, similarities[0][i].item()) for i, sentence in enumerate(sentences_to_compare)] |
|
return results |
|
|
|
|
|
iface = gr.Interface( |
|
fn=compute_similarities, |
|
inputs=[ |
|
gr.inputs.Textbox(lines=2, placeholder="Enter the original sentence here..."), |
|
gr.inputs.Textbox(lines=5, placeholder="Enter sentences to compare, separated by new lines...") |
|
], |
|
outputs=gr.outputs.Dataframe(headers=["Sentence", "Similarity Score"]), |
|
title="Sentence Similarity Checker", |
|
description="Enter an original sentence and a list of sentences to compare. The app will compute and display similarity scores for each comparison." |
|
) |
|
|
|
|
|
iface.launch() |
|
|