Spaces:
Runtime error
Runtime error
initial app
Browse files- app.py +15 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import tensorflow_text as text # Registers the ops. (needed for "bert_preprocessor")
|
3 |
+
from tensorflow_hub.hf_utils import pull_from_hub
|
4 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
5 |
+
|
6 |
+
model = pull_from_hub(repo_id="Dimitre/universal-sentence-encoder")
|
7 |
+
|
8 |
+
def get_similarity(sentence_a, sentence_b):
|
9 |
+
embed_a = model([sentence_a])
|
10 |
+
embed_b = model([sentence_b])
|
11 |
+
print(embed_a.shape, embed_b.shape)
|
12 |
+
return cosine_similarity(embed_a, embed_b)
|
13 |
+
|
14 |
+
iface = gr.Interface(fn=get_similarity, inputs=["text", "text"], outputs="text")
|
15 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
sklearn
|
2 |
+
tensorflow
|
3 |
+
tensorflow_text
|
4 |
+
git+https://github.com/dimitreOliveira/hub.git
|