innocent-charles's picture
Update app.py
062d5b7 verified
raw
history blame
1.35 kB
import gradio as gr
from sentence_transformers import SentenceTransformer, util
# Load the model
model = SentenceTransformer('sartifyllc/AviLaBSE')
# Function to compute similarities
def compute_similarities(original_sentence, sentences_to_compare):
# Encode the original sentence and the sentences to compare
embeddings_original = model.encode([original_sentence])
embeddings_sentences_to_compare = model.encode(sentences_to_compare)
# Compute cosine similarities
similarities = util.cos_sim(embeddings_original, embeddings_sentences_to_compare)
# Prepare the results as a list of tuples
results = [(sentence, similarities[0][i].item()) for i, sentence in enumerate(sentences_to_compare)]
return results
# Define the Gradio interface
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."
)
# Launch the interface
iface.launch()