vjain commited on
Commit
2980408
1 Parent(s): d56d55a

Upload 2 files

Browse files
Files changed (3) hide show
  1. .gitattributes +1 -0
  2. TA_embeddings.csv +3 -0
  3. TaBot.py +56 -0
.gitattributes CHANGED
@@ -32,3 +32,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
35
+ TA_embeddings.csv filter=lfs diff=lfs merge=lfs -text
TA_embeddings.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8afcfddb6b6aa42dd3513a2e801d676c012da0d9199825064123c6a5812048af
3
+ size 244603667
TaBot.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import openai
3
+ import pandas as pd
4
+ import numpy as np
5
+ import csv
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
+ df = pd.read_csv("TA_embeddings.csv")
10
+ df["embedding"]=df["embedding"].apply(eval).apply(np.array)
11
+ def reply(input):
12
+
13
+ input = input
14
+ input_vector = get_embedding(input, engine="text-embedding-ada-002")
15
+ df["similiarities"]=df["embedding"].apply(lambda x: cosine_similarity(x,input_vector))
16
+ data = df.sort_values("similiarities", ascending=False).head(20)
17
+ data.to_csv("sorted.csv")
18
+ context = []
19
+ for i, row in data.iterrows():
20
+ context.append(row['text'])
21
+ context
22
+ text = "\n".join(context)
23
+ context = text
24
+ prompt = f"""
25
+ Answer the following question If you don't know the answer for certain, say I don't know.
26
+ Context: {context}
27
+
28
+ Q: {input}
29
+
30
+ """
31
+ return openai.Completion.create(
32
+ prompt=prompt,
33
+ temperature=1,
34
+ max_tokens=500,
35
+ top_p=1,
36
+ frequency_penalty=0,
37
+ presence_penalty=0,
38
+ model="text-davinci-003"
39
+ )["choices"][0]["text"].strip(" \n")
40
+
41
+
42
+ input_text = gr.inputs.Textbox(label="Enter your text here")
43
+ text_output = gr.outputs.Textbox(label="Most similar text")
44
+
45
+ ui = gr.Interface(fn=reply,
46
+ inputs=input_text,
47
+ outputs=[text_output],
48
+ theme="compact",
49
+ layout="vertical",
50
+ inputs_layout="stacked",
51
+ outputs_layout="stacked",
52
+ allow_flagging=False)
53
+
54
+
55
+
56
+ ui.launch()