Spaces:
Runtime error
Runtime error
import gradio as gr | |
from sklearn.metrics.pairwise import cosine_similarity | |
def greet(array_of_vectors): | |
# [[0 1],[0 5]] | |
array_of_vectors = replace("[[", "") | |
array_of_vectors = replace("]]", "") | |
array_of_vectors = replace("[", "") | |
array_of_vectors = replace("]", "") | |
cleaned = [] | |
vecs = array_of_vectors.split(",") | |
for vec in vecs: | |
arr = vec.split(" ") | |
cleaned.append(arr) | |
similarity_matrix = cosine_similarity(cleaned, cleaned) | |
results = '' | |
for matrix in similarity_matrix: | |
results = results + str(matrix) + "\n" | |
return results | |
iface = gr.Interface(fn=greet, inputs="text", outputs="text") | |
iface.launch() |