Spaces:
Runtime error
Runtime error
johnnyfivefingers
commited on
Commit
•
ae007e6
1
Parent(s):
2cb1429
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
4 |
+
|
5 |
+
def greet(array_of_vectors):
|
6 |
+
# [[0 1],[0 5]]
|
7 |
+
array_of_vectors = replace("[[", "")
|
8 |
+
array_of_vectors = replace("]]", "")
|
9 |
+
array_of_vectors = replace("[", "")
|
10 |
+
array_of_vectors = replace("]", "")
|
11 |
+
|
12 |
+
cleaned = []
|
13 |
+
vecs = array_of_vectors.split(",")
|
14 |
+
for vec in vecs:
|
15 |
+
arr = vec.split(" ")
|
16 |
+
cleaned.append(arr)
|
17 |
+
|
18 |
+
similarity_matrix = cosine_similarity(cleaned, cleaned)
|
19 |
+
results = ''
|
20 |
+
for matrix in similarity_matrix:
|
21 |
+
results = results + str(matrix) + "\n"
|
22 |
+
|
23 |
+
|
24 |
+
return results
|
25 |
+
|
26 |
+
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
27 |
+
iface.launch()
|