innocent-charles
commited on
Commit
•
062d5b7
1
Parent(s):
d5762f3
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from sentence_transformers import SentenceTransformer, util
|
3 |
+
|
4 |
+
# Load the model
|
5 |
+
model = SentenceTransformer('sartifyllc/AviLaBSE')
|
6 |
+
|
7 |
+
# Function to compute similarities
|
8 |
+
def compute_similarities(original_sentence, sentences_to_compare):
|
9 |
+
# Encode the original sentence and the sentences to compare
|
10 |
+
embeddings_original = model.encode([original_sentence])
|
11 |
+
embeddings_sentences_to_compare = model.encode(sentences_to_compare)
|
12 |
+
|
13 |
+
# Compute cosine similarities
|
14 |
+
similarities = util.cos_sim(embeddings_original, embeddings_sentences_to_compare)
|
15 |
+
|
16 |
+
# Prepare the results as a list of tuples
|
17 |
+
results = [(sentence, similarities[0][i].item()) for i, sentence in enumerate(sentences_to_compare)]
|
18 |
+
return results
|
19 |
+
|
20 |
+
# Define the Gradio interface
|
21 |
+
iface = gr.Interface(
|
22 |
+
fn=compute_similarities,
|
23 |
+
inputs=[
|
24 |
+
gr.inputs.Textbox(lines=2, placeholder="Enter the original sentence here..."),
|
25 |
+
gr.inputs.Textbox(lines=5, placeholder="Enter sentences to compare, separated by new lines...")
|
26 |
+
],
|
27 |
+
outputs=gr.outputs.Dataframe(headers=["Sentence", "Similarity Score"]),
|
28 |
+
title="Sentence Similarity Checker",
|
29 |
+
description="Enter an original sentence and a list of sentences to compare. The app will compute and display similarity scores for each comparison."
|
30 |
+
)
|
31 |
+
|
32 |
+
# Launch the interface
|
33 |
+
iface.launch()
|