Spaces:
Runtime error
Runtime error
Update prepare_vector_dp.py
Browse files- prepare_vector_dp.py +4 -4
prepare_vector_dp.py
CHANGED
@@ -30,7 +30,7 @@ model_file = hf_hub_download(
|
|
30 |
)
|
31 |
|
32 |
# Ham 1. Tao ra vector DB tu 1 doan text
|
33 |
-
def create_db_from_text():
|
34 |
|
35 |
raw_text = "Trường Đại học Khoa học – Đại học Huế là một trong những cơ sở đào tạo và nghiên cứu hàng đầu tại khu vực miền Trung và Tây Nguyên. Được thành lập từ năm 1957, trường có bề dày truyền thống trong giảng dạy các ngành khoa học tự nhiên, xã hội và nhân văn. Với đội ngũ giảng viên giàu kinh nghiệm, cơ sở vật chất hiện đại và môi trường học tập năng động, Trường Đại học Khoa học luôn là lựa chọn uy tín của sinh viên trong và ngoài nước. Trường hiện tọa lạc tại số 77 Nguyễn Huệ, thành phố Huế – trung tâm văn hóa, giáo dục lớn của cả nước."
|
36 |
|
@@ -59,14 +59,14 @@ def create_db_from_text():
|
|
59 |
embedding_model = GPT4AllEmbeddings(model_file= model_file)
|
60 |
'''
|
61 |
|
62 |
-
embedding_model = HuggingFaceEmbeddings(model_name =
|
63 |
|
64 |
# Dua vao Faiss Vector DB
|
65 |
db = FAISS.from_texts(texts=chunks, embedding=embedding_model)
|
66 |
db.save_local(vector_dp_path)
|
67 |
return db
|
68 |
|
69 |
-
def create_dp_from_files():
|
70 |
|
71 |
print("Files in directory:", os.listdir(pdf_data_path))
|
72 |
|
@@ -81,7 +81,7 @@ def create_dp_from_files():
|
|
81 |
text_splitter = CharacterTextSplitter(chunk_size = 512, chunk_overlap = 50)
|
82 |
chunks = text_splitter.split_documents(documents)
|
83 |
|
84 |
-
embedding_model = HuggingFaceEmbeddings(model_name =
|
85 |
dp = FAISS.from_documents(chunks, embedding_model)
|
86 |
dp.save_local(vector_dp_path)
|
87 |
return dp
|
|
|
30 |
)
|
31 |
|
32 |
# Ham 1. Tao ra vector DB tu 1 doan text
|
33 |
+
def create_db_from_text(request_model):
|
34 |
|
35 |
raw_text = "Trường Đại học Khoa học – Đại học Huế là một trong những cơ sở đào tạo và nghiên cứu hàng đầu tại khu vực miền Trung và Tây Nguyên. Được thành lập từ năm 1957, trường có bề dày truyền thống trong giảng dạy các ngành khoa học tự nhiên, xã hội và nhân văn. Với đội ngũ giảng viên giàu kinh nghiệm, cơ sở vật chất hiện đại và môi trường học tập năng động, Trường Đại học Khoa học luôn là lựa chọn uy tín của sinh viên trong và ngoài nước. Trường hiện tọa lạc tại số 77 Nguyễn Huệ, thành phố Huế – trung tâm văn hóa, giáo dục lớn của cả nước."
|
36 |
|
|
|
59 |
embedding_model = GPT4AllEmbeddings(model_file= model_file)
|
60 |
'''
|
61 |
|
62 |
+
embedding_model = HuggingFaceEmbeddings(model_name = request_model)
|
63 |
|
64 |
# Dua vao Faiss Vector DB
|
65 |
db = FAISS.from_texts(texts=chunks, embedding=embedding_model)
|
66 |
db.save_local(vector_dp_path)
|
67 |
return db
|
68 |
|
69 |
+
def create_dp_from_files(request_model):
|
70 |
|
71 |
print("Files in directory:", os.listdir(pdf_data_path))
|
72 |
|
|
|
81 |
text_splitter = CharacterTextSplitter(chunk_size = 512, chunk_overlap = 50)
|
82 |
chunks = text_splitter.split_documents(documents)
|
83 |
|
84 |
+
embedding_model = HuggingFaceEmbeddings(model_name = request_model)
|
85 |
dp = FAISS.from_documents(chunks, embedding_model)
|
86 |
dp.save_local(vector_dp_path)
|
87 |
return dp
|