innocent-charles commited on
Commit
d5762f3
1 Parent(s): fd06722

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -42
app.py CHANGED
@@ -1,42 +0,0 @@
1
- from sentence_transformers import SentenceTransformer, util
2
- import gradio as gr
3
-
4
- # Load the model
5
- model = SentenceTransformer('sartifyllc/AviLaBSE')
6
-
7
- # Function to compute similarities
8
- def compute_similarity(original_sentence, sentences_to_compare):
9
- # Encode the original sentence and the sentences to compare
10
- embeddings_original = model.encode([original_sentence], convert_to_tensor=True)
11
- embeddings_sentences_to_compare = model.encode(sentences_to_compare, convert_to_tensor=True)
12
-
13
- # Compute cosine similarities
14
- similarities = util.cos_sim(embeddings_original, embeddings_sentences_to_compare)
15
-
16
- # Prepare results
17
- results = []
18
- for i, sentence in enumerate(sentences_to_compare):
19
- results.append((sentence, similarities[0][i].item()))
20
-
21
- return results
22
-
23
- # Interface using Gradio
24
- def sentence_similarity(original_sentence, sentence1, sentence2, sentence3):
25
- sentences_to_compare = [sentence1, sentence2, sentence3]
26
- results = compute_similarity(original_sentence, sentences_to_compare)
27
- return results
28
-
29
- iface = gr.Interface(
30
- fn=sentence_similarity,
31
- inputs=[
32
- gr.Textbox(label="Original Sentence"),
33
- gr.Textbox(label="Sentence 1"),
34
- gr.Textbox(label="Sentence 2"),
35
- gr.Textbox(label="Sentence 3")
36
- ],
37
- outputs=gr.Table(label="Similarity Scores", headers=["Sentence", "Similarity Score"]),
38
- title="Sentence Similarity Calculator",
39
- description="Enter an original sentence and three sentences to compare their similarity."
40
- )
41
-
42
- iface.launch()