achenyx1412 commited on
Commit
e68aadb
·
verified ·
1 Parent(s): 73d2643

Update graphrag_agent.py

Browse files
Files changed (1) hide show
  1. graphrag_agent.py +29 -14
graphrag_agent.py CHANGED
@@ -698,22 +698,37 @@ def whether_to_interact(state):
698
  else:
699
  return "stop_flow"
700
 
701
- # 创建存放目录
702
- os.makedirs("data", exist_ok=True)
703
-
704
- # 从 Hugging Face 下载 data.zip
705
- zip_path = hf_hub_download(
706
- repo_id="achenyx1412/DGADIS",
707
- filename="data.zip",
708
- repo_type="dataset",
709
- token=HF_TOKEN
710
- )
 
 
 
 
 
711
 
712
- # 解压到 data 文件夹
713
- with ZipFile(zip_path, "r") as zip_ref:
714
- zip_ref.extractall("data/")
 
 
 
 
 
 
715
 
716
- print("✅ 已成功下载并解压 data.zip")
 
 
 
 
717
 
718
  def neo4j_retrieval(state: MyState):
719
  logger.info("---NODE: neo4j_retrieval---")
 
698
  else:
699
  return "stop_flow"
700
 
701
+ # 数据存放路径
702
+ DATA_DIR = "data"
703
+ ZIP_FILE = "data.zip"
704
+
705
+ # 如果 data/ 已存在且非空,就跳过下载
706
+ if os.path.exists(DATA_DIR) and any(os.scandir(DATA_DIR)):
707
+ print("✅ 已检测到本地 data 文件夹,跳过下载。")
708
+
709
+ else:
710
+ # 如果没有解压好的 data,但有 data.zip,则直接解压
711
+ if os.path.exists(ZIP_FILE):
712
+ print("📦 检测到本地 data.zip,正在解压...")
713
+ with ZipFile(ZIP_FILE, "r") as zip_ref:
714
+ zip_ref.extractall(DATA_DIR)
715
+ print("✅ 已成功解压本地 data.zip")
716
 
717
+ else:
718
+ # 如果连 data.zip 都没有,才从 HF 下载
719
+ print("🌐 未检测到本地数据,开始从 Hugging Face 下载 data.zip...")
720
+ zip_path = hf_hub_download(
721
+ repo_id="achenyx1412/DGADIS",
722
+ filename="data.zip",
723
+ repo_type="dataset",
724
+ token=HF_TOKEN
725
+ )
726
 
727
+ # 解压
728
+ print("📦 正在解压 data.zip...")
729
+ with ZipFile(zip_path, "r") as zip_ref:
730
+ zip_ref.extractall(DATA_DIR)
731
+ print("✅ 已成功下载并解压 data.zip")
732
 
733
  def neo4j_retrieval(state: MyState):
734
  logger.info("---NODE: neo4j_retrieval---")