vjain commited on
Commit
3f8afbf
1 Parent(s): eeebb7c

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +25 -0
  2. meg_embeddings.csv +0 -0
  3. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import openai
3
+ import pandas as pd
4
+ import numpy as np
5
+
6
+ openai.api_key="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"
7
+ from openai.embeddings_utils import get_embedding
8
+ from openai.embeddings_utils import cosine_similarity
9
+
10
+ def similarity(input_text):
11
+ df= pd.read_csv("meg_embeddings.csv")
12
+ df['embedding'] = df['embedding'].apply(eval).apply(np.array)
13
+ input = input_text
14
+ input_vector = get_embedding(input, engine="text-embedding-ada-002")
15
+ df["similarities"] = df['embedding'].apply(lambda x: cosine_similarity(x, input_vector))
16
+ sorted_df =df.sort_values("similarities", ascending=False)
17
+ top_row = sorted_df.loc[0]
18
+ return sorted_df.iloc[0]["text"]
19
+
20
+ input_text = gr.inputs.Textbox(label="Input Text")
21
+
22
+
23
+ output_label = gr.outputs.Label(label="Similarity Text")
24
+
25
+ gr.Interface(fn=similarity, inputs=[input_text], outputs=output_label, title="Semantic Similarity Checker", description="Check if input text is semantically similar to file saved locally using Ada text embeddings.").launch()
meg_embeddings.csv ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ openai
2
+ plotly
3
+ scipy