Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ model = hub.load(model_url)
|
|
9 |
|
10 |
def embed_text(text: str) -> dict:
|
11 |
embeddings = model(text)
|
12 |
-
return embeddings.numpy().tolist()
|
13 |
|
14 |
embed_text_inter = gr.Interface(
|
15 |
fn = embed_text,
|
@@ -19,11 +19,16 @@ embed_text_inter = gr.Interface(
|
|
19 |
)
|
20 |
|
21 |
def distance(text_1: str, text_2: str) -> float:
|
22 |
-
embeddings_1 =
|
23 |
-
embeddings_2 =
|
24 |
-
|
|
|
|
|
|
|
|
|
25 |
return dist
|
26 |
|
|
|
27 |
distance_inter = gr.Interface(
|
28 |
fn = distance,
|
29 |
inputs = ["text", "text"],
|
|
|
9 |
|
10 |
def embed_text(text: str) -> dict:
|
11 |
embeddings = model(text)
|
12 |
+
return embeddings.numpy().tolist()[0]
|
13 |
|
14 |
embed_text_inter = gr.Interface(
|
15 |
fn = embed_text,
|
|
|
19 |
)
|
20 |
|
21 |
def distance(text_1: str, text_2: str) -> float:
|
22 |
+
embeddings_1 = embed_text(text_1)
|
23 |
+
embeddings_2 = embed_text(text_2)
|
24 |
+
|
25 |
+
dist = 0
|
26 |
+
for i in range(len(embeddings_1)):
|
27 |
+
dist += (embeddings_1[i] - embeddings_2[i]) ** 2
|
28 |
+
dist = math.sqrt(dist)
|
29 |
return dist
|
30 |
|
31 |
+
|
32 |
distance_inter = gr.Interface(
|
33 |
fn = distance,
|
34 |
inputs = ["text", "text"],
|