Spaces:
Sleeping
Sleeping
Download benchmark_challenge_generation.py from refaelz/legacy-code-challenge-v2: direct link, hf CLI and curl.
- Browser
- Download file 1.59 kB
-
https://huggingface.co/spaces/refaelz/legacy-code-challenge-v2/resolve/main/benchmark_challenge_generation.py
- Command line
-
hf download hf://spaces/refaelz/legacy-code-challenge-v2/benchmark_challenge_generation.py
-
curl -L -o benchmark_challenge_generation.py https://huggingface.co/spaces/refaelz/legacy-code-challenge-v2/resolve/main/benchmark_challenge_generation.py
1.59 kB
| import os | |
| import time | |
| import json | |
| from challenge_runtime import create_challenge | |
| REPOSITORY = os.getenv("BENCHMARK_REPOSITORY", "https://github.com/pallets/flask") | |
| NUM_BUGS = int(os.getenv("BENCHMARK_NUM_BUGS", "2")) | |
| DEPTH = int(os.getenv("BENCHMARK_DEPTH", "5")) | |
| REFACTORING = os.getenv("BENCHMARK_REFACTORING", "1") == "1" | |
| stage_events = [] | |
| started = time.monotonic() | |
| def callback(progress, message): | |
| stage_events.append({ | |
| "progress": progress, | |
| "message": message, | |
| "elapsed_seconds": round(time.monotonic() - started, 3), | |
| }) | |
| try: | |
| workspace = create_challenge( | |
| github_url=REPOSITORY, | |
| nesting_level=DEPTH, | |
| num_bugs=NUM_BUGS, | |
| refactoring_enabled=REFACTORING, | |
| debug_mode=True, | |
| progress_callback=callback, | |
| ) | |
| elapsed = round(time.monotonic() - started, 3) | |
| print(json.dumps({ | |
| "status": "success", | |
| "repository": REPOSITORY, | |
| "num_bugs": NUM_BUGS, | |
| "depth": DEPTH, | |
| "refactoring": REFACTORING, | |
| "workspace": workspace, | |
| "elapsed_seconds": elapsed, | |
| "events": stage_events, | |
| }, ensure_ascii=False, indent=2)) | |
| except Exception as exc: | |
| elapsed = round(time.monotonic() - started, 3) | |
| print(json.dumps({ | |
| "status": "failed", | |
| "repository": REPOSITORY, | |
| "num_bugs": NUM_BUGS, | |
| "depth": DEPTH, | |
| "refactoring": REFACTORING, | |
| "error_type": type(exc).__name__, | |
| "error": str(exc), | |
| "elapsed_seconds": elapsed, | |
| "events": stage_events, | |
| }, ensure_ascii=False, indent=2)) | |