File size: 659 Bytes
b1f3107 2567765 b1f3107 1aeeff7 ed2cc23 1aeeff7 b1f3107 1aeeff7 2567765 b1f3107 ed2cc23 0a1635b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import gradio as gr
from transformers.utils import logging
logging.set_verbosity_error()
from sentence_transformers import SentenceTransformer
from sentence_transformers import util
def compare(input):
lines = input.splitlines()
embeddings1 = model.encode(lines[0], convert_to_tensor=True)
embeddings2 = model.encode(lines[1], convert_to_tensor=True)
cosine_scores = util.cos_sim(embeddings1, embeddings2)
return "Score: {:.4f} \t\t {} \t\t {}".format(cosine_scores[0][0], lines[0], lines[1])
model = SentenceTransformer("all-MiniLM-L6-v2")
demo = gr.Interface(fn=compare, inputs="textarea", outputs="text")
demo.launch()
gr.close_all() |