savasy commited on
Commit
4da19d6
1 Parent(s): 4cc7872

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import numpy as np
3
+ from sentence_transformers import SentenceTransformer
4
+ from scipy.spatial.distance import cdist
5
+ import gradio as gr
6
+
7
+
8
+ df=pd.read_csv("english_idioms.csv")
9
+ meaning=list(df.meaning)
10
+ idioms= list(df.idioms)
11
+
12
+ model = SentenceTransformer("all-mpnet-base-v2")
13
+ idiom_meaning_embeddings=vectors = np.load("vectors.npy")
14
+
15
+ def get_best(query):
16
+ query_embedding = model.encode([query])
17
+ distances = cdist(query_embedding, idiom_meaning_embeddings, "cosine")[0]
18
+ ind = np.argsort(distances, axis=0)
19
+ return idioms[ind[0]], distances[ind[0]], meaning[ind[0]]
20
+
21
+ 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()
22
+