Dimitre's picture
initial app
00dd6df
raw
history blame
576 Bytes
import gradio as gr
import tensorflow_text as text # Registers the ops. (needed for "bert_preprocessor")
from tensorflow_hub.hf_utils import pull_from_hub
from sklearn.metrics.pairwise import cosine_similarity
model = pull_from_hub(repo_id="Dimitre/universal-sentence-encoder")
def get_similarity(sentence_a, sentence_b):
embed_a = model([sentence_a])
embed_b = model([sentence_b])
print(embed_a.shape, embed_b.shape)
return cosine_similarity(embed_a, embed_b)
iface = gr.Interface(fn=get_similarity, inputs=["text", "text"], outputs="text")
iface.launch()