helliun
commited on
Commit
·
ec16ff2
0
Parent(s):
Duplicate from helliun/personalChatGPT
Browse files- .gitattributes +34 -0
- README.md +13 -0
- app.py +66 -0
- requirements.txt +4 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz 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
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: PersonalChatGPT
|
3 |
+
emoji: 📈
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: indigo
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.19.1
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
duplicated_from: helliun/personalChatGPT
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pinecone
|
2 |
+
from sentence_transformers import SentenceTransformer
|
3 |
+
import openai
|
4 |
+
import json
|
5 |
+
import gradio as gr
|
6 |
+
|
7 |
+
pinecone.init(api_key="60422c7f-218d-4343-8158-5b4df9559628", environment="us-east1-gcp")
|
8 |
+
index = pinecone.Index("chatgpt-memory")
|
9 |
+
|
10 |
+
openai.api_key = "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"
|
11 |
+
|
12 |
+
embmodel = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
|
13 |
+
|
14 |
+
|
15 |
+
def get_response(input, conversation):
|
16 |
+
user_message = input
|
17 |
+
if conversation!=[]:
|
18 |
+
assistant_message = conversation[-1]["content"]
|
19 |
+
else:
|
20 |
+
assistant_message = ""
|
21 |
+
messages = [{"role": "system", "content": "You are the assistant of 22 year old Henry Leonardi. You have access to memories from previous conversations."}]
|
22 |
+
embed = embmodel.encode([user_message]).tolist()[0]
|
23 |
+
matches = index.query(embed, top_k=5, include_metadata=True)["matches"]
|
24 |
+
try:
|
25 |
+
best = [m["id"] for m in matches][:3]
|
26 |
+
for b in best:
|
27 |
+
messages.extend(eval(b))
|
28 |
+
except:
|
29 |
+
messages = []
|
30 |
+
pair = []
|
31 |
+
d = {"role":"user","content":user_message}
|
32 |
+
conversation.append(d)
|
33 |
+
messages.extend(conversation[-6:])
|
34 |
+
d["content"] = d["content"][:200]
|
35 |
+
pair.append(d)
|
36 |
+
assistant_message = openai.ChatCompletion.create(model="gpt-3.5-turbo",messages=messages)["choices"][0]["message"].to_dict()["content"]
|
37 |
+
d = {"role":"assistant","content":assistant_message}
|
38 |
+
conversation.append(d)
|
39 |
+
response = d["content"]
|
40 |
+
d["content"] = d["content"][:200]
|
41 |
+
pair.append(d)
|
42 |
+
if pair[0]["content"]!="bye":
|
43 |
+
pair_str = str(json.dumps(pair).encode('utf-8'))[2:-1]
|
44 |
+
index.upsert([(pair_str, embmodel.encode([pair]).tolist()[0])])
|
45 |
+
return response
|
46 |
+
|
47 |
+
def conv(input, history=[]):
|
48 |
+
conversation = []
|
49 |
+
for item in history:
|
50 |
+
conversation.append({"role":"user","content":item[0]})
|
51 |
+
conversation.append({"role":"assistant","content":item[1]})
|
52 |
+
output = get_response(input, conversation)
|
53 |
+
history.append((input, output))
|
54 |
+
return history, history
|
55 |
+
|
56 |
+
block = gr.Blocks()
|
57 |
+
|
58 |
+
with block:
|
59 |
+
gr.Markdown("""<h1><center>Your Personal Assistant</center></h1>""")
|
60 |
+
chatbot = gr.Chatbot()
|
61 |
+
message = gr.Textbox(placeholder="prompt")
|
62 |
+
state = gr.State([])
|
63 |
+
submit = gr.Button("SEND")
|
64 |
+
submit.click(conv, inputs=[message, state], outputs=[chatbot, state])
|
65 |
+
|
66 |
+
block.launch(inline = True)
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pinecone-client
|
2 |
+
sentence-transformers
|
3 |
+
openai
|
4 |
+
gradio
|