Download runtime/graphkit/__main__.py from VISAI-AI/icj-citation-graph: direct link, hf CLI and curl.
- Browser
- Download file 2.47 kB
-
https://huggingface.co/datasets/VISAI-AI/icj-citation-graph/resolve/main/runtime/graphkit/__main__.py
- Command line
-
hf download hf://datasets/VISAI-AI/icj-citation-graph/runtime/graphkit/__main__.py
-
curl -L -o __main__.py https://huggingface.co/datasets/VISAI-AI/icj-citation-graph/resolve/main/runtime/graphkit/__main__.py
2.47 kB
| import argparse | |
| import json | |
| import os | |
| from ._graph import Graph | |
| from ._state import locked_state | |
| from .config import TARGETS | |
| from .download import fetch | |
| from .embedding import embed_graph | |
| from .indexes import create_indexes, inspect_graph | |
| from .parquet import load_vectors | |
| def positive(value): | |
| value = int(value) | |
| if value < 1: | |
| raise argparse.ArgumentTypeError('must be positive') | |
| return value | |
| def main(): | |
| parser = argparse.ArgumentParser(description='Restore vectors and manage the ICJ graph. API calls are explicit.') | |
| commands = parser.add_subparsers(dest='command', required=True) | |
| download = commands.add_parser('fetch') | |
| download.add_argument('--data-dir', default='/dataset') | |
| download.add_argument('--revision', default=os.getenv('ICJ_REVISION', 'main')) | |
| download.add_argument('--vectors', action='store_true') | |
| commands.add_parser('inspect') | |
| for name in ['vectors', 'embed', 'indexes']: | |
| child = commands.add_parser(name) | |
| child.add_argument('--targets', nargs='+', choices=list(TARGETS), default=list(TARGETS)) | |
| if name == 'indexes': | |
| child.add_argument('--property') | |
| child.add_argument('--timeout', type=positive, default=3600) | |
| else: | |
| child.add_argument('--batch-size', type=positive, default=64) | |
| child.add_argument('--limit', type=positive, help='Maximum newly added vectors per target in this invocation; omit to process all.') | |
| if name == 'vectors': | |
| child.add_argument('--data-dir', default='/dataset') | |
| else: | |
| child.add_argument('--property', default='api_embedding') | |
| args = parser.parse_args() | |
| if args.command == 'fetch': | |
| fetch(args.data_dir, args.revision, args.vectors) | |
| return | |
| graph = Graph() | |
| try: | |
| if args.command == 'inspect': | |
| print(json.dumps(inspect_graph(graph), indent=2)) | |
| return | |
| with locked_state(os.getenv('STATE_DIR', '/state')) as cache: | |
| if args.command == 'vectors': | |
| load_vectors(graph, args.targets, args.data_dir, args.batch_size, args.limit) | |
| elif args.command == 'embed': | |
| embed_graph(graph, args.targets, cache, args.property, args.batch_size, args.limit) | |
| else: | |
| create_indexes(graph, args.targets, args.property, args.timeout) | |
| finally: | |
| graph.close() | |
| if __name__ == '__main__': | |
| main() | |