Download tools.py from THED1/Ok2: direct link, hf CLI and curl.
- Browser
- Download file 656 Bytes
-
https://huggingface.co/spaces/THED1/Ok2/resolve/main/tools.py
- Command line
-
hf download hf://spaces/THED1/Ok2/tools.py
-
curl -L -o tools.py https://huggingface.co/spaces/THED1/Ok2/resolve/main/tools.py
656 Bytes
| import subprocess | |
| from pathlib import Path | |
| WORKSPACE = Path("/workspace") | |
| def read_file(path): | |
| return (WORKSPACE / path).read_text() | |
| def write_file(path, content): | |
| p = WORKSPACE / path | |
| p.parent.mkdir(parents=True, exist_ok=True) | |
| p.write_text(content) | |
| return "ok" | |
| def list_files(): | |
| return [str(x) for x in WORKSPACE.rglob("*")] | |
| def run_command(cmd): | |
| result = subprocess.run( | |
| cmd, | |
| shell=True, | |
| cwd=WORKSPACE, | |
| capture_output=True, | |
| text=True, | |
| timeout=600 | |
| ) | |
| return { | |
| "stdout": result.stdout, | |
| "stderr": result.stderr, | |
| "code": result.returncode | |
| } |