Download scripts/seed.py from Prerna43/ai: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/spaces/Prerna43/ai/resolve/main/scripts/seed.py
- Command line
-
hf download hf://spaces/Prerna43/ai/scripts/seed.py
-
curl -L -o seed.py https://huggingface.co/spaces/Prerna43/ai/resolve/main/scripts/seed.py
1.3 kB
| from __future__ import annotations | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| import requests | |
| def index_local(api_url: str, path: str) -> dict: | |
| response = requests.post( | |
| f"{api_url.rstrip('/')}/repos/local", | |
| json={"path": str(Path(path).resolve())}, | |
| timeout=240, | |
| ) | |
| response.raise_for_status() | |
| return response.json() | |
| def index_github(api_url: str, url: str) -> dict: | |
| response = requests.post( | |
| f"{api_url.rstrip('/')}/repos/github", | |
| json={"url": url}, | |
| timeout=300, | |
| ) | |
| response.raise_for_status() | |
| return response.json() | |
| def main() -> None: | |
| parser = argparse.ArgumentParser(description="Seed the app by indexing a repository.") | |
| parser.add_argument("--api-url", default="http://localhost:8000/api") | |
| group = parser.add_mutually_exclusive_group(required=True) | |
| group.add_argument("--local-path", help="Local repository path to index.") | |
| group.add_argument("--github-url", help="GitHub repository URL to clone and index.") | |
| args = parser.parse_args() | |
| if args.local_path: | |
| summary = index_local(args.api_url, args.local_path) | |
| else: | |
| summary = index_github(args.api_url, args.github_url) | |
| print(json.dumps(summary, indent=2)) | |
| if __name__ == "__main__": | |
| main() | |