Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,20 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from sentence_transformers import SentenceTransformer, util
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
model = SentenceTransformer("all-
|
| 6 |
|
| 7 |
def compare_sentences(sentence_a, sentence_b):
|
| 8 |
emb = model.encode([sentence_a, sentence_b], convert_to_tensor=True)
|
| 9 |
score = util.pytorch_cos_sim(emb[0], emb[1]).item()
|
| 10 |
-
return f"{score * 100:.2f}%" #
|
| 11 |
|
| 12 |
iface = gr.Interface(
|
| 13 |
fn=compare_sentences,
|
| 14 |
inputs=["text", "text"],
|
| 15 |
outputs="text",
|
| 16 |
-
title="Sentence Similarity Checker",
|
| 17 |
-
description="Enter two sentences to compare their
|
| 18 |
)
|
| 19 |
|
| 20 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from sentence_transformers import SentenceTransformer, util
|
| 3 |
|
| 4 |
+
# Use a more powerful model for paraphrasing and semantic similarity
|
| 5 |
+
model = SentenceTransformer("sentence-transformers/all-mpnet-base-v2")
|
| 6 |
|
| 7 |
def compare_sentences(sentence_a, sentence_b):
|
| 8 |
emb = model.encode([sentence_a, sentence_b], convert_to_tensor=True)
|
| 9 |
score = util.pytorch_cos_sim(emb[0], emb[1]).item()
|
| 10 |
+
return f"{score * 100:.2f}%" # Similarity score as percentage
|
| 11 |
|
| 12 |
iface = gr.Interface(
|
| 13 |
fn=compare_sentences,
|
| 14 |
inputs=["text", "text"],
|
| 15 |
outputs="text",
|
| 16 |
+
title="Sentence Similarity Checker (MPNet Model)",
|
| 17 |
+
description="Enter two sentences to compare their meaning using a powerful transformer model. Score is shown as a percent."
|
| 18 |
)
|
| 19 |
|
| 20 |
iface.launch()
|