Spaces:
Sleeping
Sleeping
Update vlog4chat.py
Browse files- vlog4chat.py +2 -15
vlog4chat.py
CHANGED
@@ -29,20 +29,6 @@ from typing import Any, Dict, List, Mapping, Optional
|
|
29 |
from langchain.memory import ConversationBufferMemory
|
30 |
from langchain import LLMChain, PromptTemplate
|
31 |
|
32 |
-
import torch
|
33 |
-
|
34 |
-
def map_to_cpu(obj):
|
35 |
-
if isinstance(obj, torch.Tensor):
|
36 |
-
return obj.to(torch.device('cpu'))
|
37 |
-
elif isinstance(obj, dict):
|
38 |
-
return {k: map_to_cpu(v) for k, v in obj.items()}
|
39 |
-
elif isinstance(obj, list):
|
40 |
-
return [map_to_cpu(i) for i in obj]
|
41 |
-
elif isinstance(obj, tuple):
|
42 |
-
return tuple(map_to_cpu(i) for i in obj)
|
43 |
-
else:
|
44 |
-
return obj
|
45 |
-
|
46 |
warnings.filterwarnings("ignore", category=UserWarning)
|
47 |
B_INST, E_INST = "[INST]", "[/INST]"
|
48 |
B_SYS, E_SYS = "<<SYS>>\n", "\n<</SYS>>\n\n"
|
@@ -170,7 +156,8 @@ class Vlogger4chat :
|
|
170 |
#text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50)
|
171 |
#chunks = text_splitter.split_documents(raw_documents)
|
172 |
#self.vector_storage = FAISS.from_documents(chunks, self.my_embedding)
|
173 |
-
|
|
|
174 |
vector_storage =pickle.load(f)
|
175 |
self.vector_storage = map_to_cpu(vector_storage)
|
176 |
self.chain = ConversationalRetrievalChain.from_llm(self.llm, self.vector_storage.as_retriever(), return_source_documents=True)
|
|
|
29 |
from langchain.memory import ConversationBufferMemory
|
30 |
from langchain import LLMChain, PromptTemplate
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
warnings.filterwarnings("ignore", category=UserWarning)
|
33 |
B_INST, E_INST = "[INST]", "[/INST]"
|
34 |
B_SYS, E_SYS = "<<SYS>>\n", "\n<</SYS>>\n\n"
|
|
|
156 |
#text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50)
|
157 |
#chunks = text_splitter.split_documents(raw_documents)
|
158 |
#self.vector_storage = FAISS.from_documents(chunks, self.my_embedding)
|
159 |
+
pkl_path = os.path.join(self.data_dir, f"{video_id}.pkl")
|
160 |
+
with open(pkl_path, 'rb') as f:
|
161 |
vector_storage =pickle.load(f)
|
162 |
self.vector_storage = map_to_cpu(vector_storage)
|
163 |
self.chain = ConversationalRetrievalChain.from_llm(self.llm, self.vector_storage.as_retriever(), return_source_documents=True)
|