Spaces:
Sleeping
Sleeping
Update file_loader.py
Browse files- file_loader.py +25 -4
file_loader.py
CHANGED
@@ -12,6 +12,26 @@ from helpers import (
|
|
12 |
scrape_website, # Xử lý dữ liệu từ web
|
13 |
)
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
def get_vectorstore():
|
17 |
### Xử lý tất cả các tài liệu và nhét vào database
|
@@ -20,10 +40,11 @@ def get_vectorstore():
|
|
20 |
|
21 |
all_splits = [] # Khởi tạo danh sách lưu kết quả
|
22 |
print("Feeding relevent websites' contents")
|
23 |
-
#
|
24 |
-
|
25 |
-
#
|
26 |
-
|
|
|
27 |
|
28 |
print('Feeding .docx files')
|
29 |
for i, file_path in enumerate(tqdm(docx_files, desc="Đang xử lý", unit="file")):
|
|
|
12 |
scrape_website, # Xử lý dữ liệu từ web
|
13 |
)
|
14 |
|
15 |
+
import json
|
16 |
+
|
17 |
+
SCRAPED_DATA_PATH = "scraped_data.json"
|
18 |
+
|
19 |
+
def get_scraped_data(base_urls):
|
20 |
+
"""Tự động tải dữ liệu scrape từ file nếu có, nếu không thì scrape lại."""
|
21 |
+
if os.path.exists(SCRAPED_DATA_PATH):
|
22 |
+
print("🔄 Loading scraped website contents from file...")
|
23 |
+
with open(SCRAPED_DATA_PATH, "r", encoding="utf-8") as f:
|
24 |
+
return json.load(f)
|
25 |
+
|
26 |
+
print("🌍 Scraping websites...")
|
27 |
+
website_contents = scrape_website(base_urls)
|
28 |
+
|
29 |
+
# Lưu lại dữ liệu để lần sau không cần scrape
|
30 |
+
with open(SCRAPED_DATA_PATH, "w", encoding="utf-8") as f:
|
31 |
+
json.dump(website_contents, f, ensure_ascii=False, indent=4)
|
32 |
+
|
33 |
+
return website_contents
|
34 |
+
|
35 |
|
36 |
def get_vectorstore():
|
37 |
### Xử lý tất cả các tài liệu và nhét vào database
|
|
|
40 |
|
41 |
all_splits = [] # Khởi tạo danh sách lưu kết quả
|
42 |
print("Feeding relevent websites' contents")
|
43 |
+
#
|
44 |
+
base_urls =['https://fda.neu.edu.vn/hoi-nghi-khoa-hoc-cong-nghe-dai-hoc-kinh-te-quoc-dan-nam-2025/']
|
45 |
+
# ['https://nct.neu.edu.vn/', 'https://fsf.neu.edu.vn/', 'https://mfe.neu.edu.vn/', 'https://mis.neu.edu.vn/', 'https://fda.neu.edu.vn/', 'https://khoathongke.neu.edu.vn/', 'https://fit.neu.edu.vn/']
|
46 |
+
website_contents = get_scraped_data(base_urls=base_urls)
|
47 |
+
all_splits += website_contents
|
48 |
|
49 |
print('Feeding .docx files')
|
50 |
for i, file_path in enumerate(tqdm(docx_files, desc="Đang xử lý", unit="file")):
|