Spaces:
Runtime error
Runtime error
import pandas as pd | |
import numpy as np | |
from sentence_transformers import SentenceTransformer | |
from scipy.spatial.distance import cdist | |
import gradio as gr | |
df=pd.read_csv("english_idioms.csv") | |
meaning=list(df.meaning) | |
idioms= list(df.idioms) | |
model = SentenceTransformer("all-mpnet-base-v2") | |
idiom_meaning_embeddings=vectors = np.load("vectors.npy") | |
def get_best(query): | |
query_embedding = model.encode([query]) | |
distances = cdist(query_embedding, idiom_meaning_embeddings, "cosine")[0] | |
ind = np.argsort(distances, axis=0) | |
return idioms[ind[0]], distances[ind[0]], meaning[ind[0]] | |
gr.Interface(fn=get_best, inputs=[gr.Text(label="Enter a descriptive sentence for the idiom you're looking for",placeholder="I feel sick!" )], outputs=[gr.Text(label="Idiom"),gr.Number(label="Distance Score"), gr.Text(label="Idiom Explanation")]).launch() | |