Download scripts/build_graph.py from ZhangNguyen/Legislation_GraphRag: direct link, hf CLI and curl.
- Browser
- Download file 1.52 kB
-
https://huggingface.co/spaces/ZhangNguyen/Legislation_GraphRag/resolve/main/scripts/build_graph.py
- Command line
-
hf download hf://spaces/ZhangNguyen/Legislation_GraphRag/scripts/build_graph.py
-
curl -L -o build_graph.py https://huggingface.co/spaces/ZhangNguyen/Legislation_GraphRag/resolve/main/scripts/build_graph.py
1.52 kB
| from __future__ import annotations | |
| import argparse | |
| import json | |
| import logging | |
| import os | |
| # Giảm log nhiễu từ grpc/absl nếu có trong dependency tree. | |
| os.environ.setdefault("GRPC_VERBOSITY", "ERROR") | |
| os.environ.setdefault("GLOG_minloglevel", "2") | |
| os.environ.setdefault("TF_CPP_MIN_LOG_LEVEL", "3") | |
| def main() -> None: | |
| logging.basicConfig( | |
| level=logging.INFO, | |
| format="%(asctime)s | %(levelname)s | %(name)s | %(message)s", | |
| ) | |
| logger = logging.getLogger(__name__) | |
| logger.info("build_graph CLI started") | |
| # Import trễ để đảm bảo logger đã bật trước khi runtime bắt đầu làm việc. | |
| from src.app.runtime import build_runtime_graph, get_runtime_status | |
| parser = argparse.ArgumentParser(description="Build runtime graph before starting server.") | |
| parser.add_argument("--input_dir", type=str, default=None) | |
| parser.add_argument("--glob", type=str, default=None) | |
| parser.add_argument("--workers", type=int, default=4) | |
| args = parser.parse_args() | |
| graph = build_runtime_graph( | |
| input_dir=args.input_dir, | |
| glob_pattern=args.glob, | |
| max_workers=args.workers, | |
| ) | |
| status = get_runtime_status() | |
| print( | |
| json.dumps( | |
| { | |
| "graph_nodes": len(graph.get("nodes", [])), | |
| "graph_edges": len(graph.get("edges", [])), | |
| "status": status, | |
| }, | |
| ensure_ascii=False, | |
| indent=2, | |
| ) | |
| ) | |
| if __name__ == "__main__": | |
| main() | |